【发布时间】:2020-08-11 19:34:21
【问题描述】:
当我尝试运行以下函数时,我收到错误“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()什么也不返回,因为查询和您的一样失败。其他作者只是没有注意到它。这本质上是同一个问题,因此值得将这两者联系起来。 -
是的,它们的联系是因为答案是相同的,但是根据问题无法知道