问题描述
我遇到一个奇怪的问题,我只是没有找到解决方案.问题在于,准备好的sql语句未绑定值,参数,甚至没有将它们传递给execute函数.而是插入':blah'占位符.如我所说,我尝试了bindParam,bindValue和此方法,但都没有结果.但是,我现在将再次尝试所有这些.
I am having a strange issue that I am just not finding a solution to. The problem is that the prepared sql statement is not binding in values, parameters or even passing them through the execute function. Instead, it inserts the ':blah' placeholder. As I said, I have tried bindParam, bindValue and this method all without result. However, I will try them all again now.
我在执行调用之前输出了要发送的参数.
I outputted the parameters being sent right before the execute call.
Array ( [:username] => schenn [:salt] => NW5552wekj5155cNr52O54q56 [:hashpass] => 5e54240aec6294873d11d6ac3e5b135136a1b671 [:email] => [email protected] [:state] => OR [:country] => USA [:last_login] => 12/08/2011 )
下面是代码:
$query = "INSERT INTO player_acct (username, salt, hashpass, email, state, country, last_login)
VALUES (':username', ':salt', ':hashpass', ':email', ':state', ':country', ':last_login')";
$stmt = $pdoI->prepare($query);
$params = array(":username" => $this->username, ":salt" => $this->salt, ":hashpass" => $this->hashpass,
":email" => $this->email, ":state" => $this->state, ":country" => $this->country, ":last_login" => $this->last_login );
$stmt->execute($params);
推荐答案
您不应该在SQL中引用占位符.尝试将以下内容作为您的SQL字符串:
You shouldnt be quoting the placeholders in the SQL. Try the following as your SQL string:
$query = "INSERT INTO player_acct (username, salt, hashpass, email, state, country,
last_login) VALUES (:username, :salt, :hashpass, :email, :state, :country, :last_login)";
这篇关于在将参数绑定到PDO语句时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!