azegurb 1 Posting Whiz in Training

Hi there,
recently I have created stored procedure in Postgres Sql which deals about with hashing passwords. When used via pgAdmin tool it works like a charm as stated below.

SELECT horeca_user.update_token(
    1, //user_id
    1, //type
    'sdsfsdfs' //token
)

I have also installed extension pgcrypto.
It works when called via pgadmin tool, but not inside laravel app as stated below my php code.

$token=\DB::select("SELECT * from \"horeca_user\".update_token('$type', '$user_id', '$token')");

and finally this is my procedure code.

CREATE OR REPLACE FUNCTION horeca_user.update_token(tp integer,userid integer,token character varying)
    RETURNS character varying
    LANGUAGE 'plpgsql' VOLATILE
    PARALLEL UNSAFE
    COST 100
AS $BODY$ 
DECLARE uid INTEGER;
DECLARE tok character varying;
BEGIN
    uid:=0;
    Select count(*) as total from horeca_user.user_tokens where user_id=$2 into uid;

    if uid=0 THEN
       Insert into horeca_user.user_tokens(id, user_id, tip) values($3, $2, $1);
     else
       Update horeca_user.user_tokens set id=$3, tip=$1 where user_id=$2;
     END IF;

     SELECT encode(digest(token, 'sha256'), 'hex') as tt into tok;

     return tok;
END

$BODY$;

Thanks in advance!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.