【发布时间】:2013-08-04 10:06:48
【问题描述】:
我在尝试运行以下函数时收到错误“SQLSTATE[HY093]: Invalid parameter number”:
function add_persist($db, $user_id) {
$hash = md5("per11".$user_id."sist11".time());
$future = time()+(60*60*24*14);
$sql = "INSERT INTO persist (user_id, hash, expire) VALUES (:user_id, :hash, :expire) ON DUPLICATE KEY UPDATE hash=:hash";
$stm = $db->prepare($sql);
$stm->execute(array(":user_id" => $user_id, ":hash" => $hash, ":expire" => $future));
return $hash;
}
我觉得这很简单,我只是没听懂。有什么想法吗?
【问题讨论】:
-
You cannot use a named parameter marker of the same name twice in a prepared statement.http://php.net/manual/en/pdo.prepare.php -
我知道该帖子的答案也可以回答我的问题,但我的问题绝对不可能重复。
-
在另一个问题中,
fetchAll()没有返回任何内容,因为查询与您的一样失败。其他作者只是没有注意到它。这本质上是同一个问题,因此值得将这两者联系起来。 -
是的,它们之间的联系是因为答案是相同的,但根据问题无法知道