PDO Prepare statement not processing parameters

[亡魂溺海] 提交于 2020-01-06 08:33:26

问题


I've exhausted all efforts at what appears to be a trivial problem, but gotten nowhere.

There is a simple Prepare statement:

$qry = $core->db->prepare("SELECT * FROM users WHERE email = '?'");
$qry->execute(array('email@address.com'));

However, no rows are returned. Running the query with the parameters hardcoded into the query results in a successful selection of one row. I've tryed many different methods of doing the prepare, but even it this most simple form it isn't working.

The PDO object is stored in a singleton called Core. PDO is using the mysql driver.


回答1:


Remove quotes from the query:

("SELECT * FROM users WHERE email = ?");

The reason to use placeholders (? symbol) is to forget about quotes. PDO will add them automatically.



来源:https://stackoverflow.com/questions/2434560/pdo-prepare-statement-not-processing-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!