PHP postgres传递参数
我是PHP的新手,正在使用一些现有代码。代码的作者向我建议:PHP postgres传递参数,php,postgresql,postgresql-9.2,Php,Postgresql,Postgresql 9.2,我是PHP的新手,正在使用一些现有代码。代码的作者向我建议: // 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_prepar
// 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);
注意:prepare_db和所有其他函数_db都是作者为兼容MYSQL、Postgres和SQLITE而创建的PDO函数
我的病例是研究生。然而,execute产生了这个错误,经过几天的阅读,我仍然不明白为什么。我做错了什么
The DBMS server said: SQLSTATE[42601]: Syntax error: 7
ERROR: syntax error at or near "$1" LINE 1: SET SESSION my.tech = $1 ^
我认为这与PostgreSQL无关。这就是PHP,它在所有方面都很糟糕
// My lines
$_cp_sql .= " SET SESSION "."my.tech"." = :my_current_user";
首先,这与
$_cp_sql .= " SET SESSION my.tech = :my_current_user";
其次,我不认为SET需要事先准备好的语句。从
任何SELECT、INSERT、UPDATE、DELETE或VALUES语句
因此,馈送到prepare_db和execute_prepared_db集合并没有任何意义
在此之前,php是一种可怕的语言,我甚至不知道是什么提供了prepare_db、bind_param_db还是execute_prepared_db。我相信,尽管作者有这样的意图,但作者并不理解SQL。我会在其他地方寻找不同的代码