0

I am a rookie at PHP and I am using some existing code. The author of the code suggested to me:

// My lines
$_cp_sql .= " SET SESSION "."my.tech"." = :my_current_user";
$res_prepare = prepare_db($conn, $_cp_sql);
$res_bind = bind_param_db($res_prepare, ':my_current_user' , $current_user );
$res_ex = execute_prepared_db($res_prepare,0);

Note: prepare_db and all the other functions_db are PDO functions that the author created to be compatible with MYSQL, Postgres, and SQLITE.

My case is Postgres. However the execute produces this error, and after days of reading, I still do not understand why. What am I doing wrong?

The DBMS server said: SQLSTATE[42601]: Syntax error: 7 
ERROR: syntax error at or near "$1" LINE 1: SET SESSION my.tech = $1 ^

1 Answer 1

1

I don't think this has anything to do with PostgreSQL. This is PHP, which is horrible at everything.

// My lines
$_cp_sql .= " SET SESSION "."my.tech"." = :my_current_user";

First that's the same as..

$_cp_sql .= " SET SESSION my.tech = :my_current_user";

Second, I don't think SET takes prepared statements. From the docs on PREPARE

Any SELECT, INSERT, UPDATE, DELETE, or VALUES statement.

So feeding to prepare_db and execute_prepared_db a SET doesn't make any sense anyway.

Shy of that, php is a horrible language and I'm not even sure what provides you prepare_db, bind_param_db, or execute_prepared_db. I believe, despite the author intentions, that the author doesn't understand SQL. I would look for different code elsewhere.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.