[英]PDO update returns success, but doesn't update the database
I'm using PDO to update a column in a table. 我正在使用PDO更新表中的列。 It runs fine, and execute()
returns 1
(success). 它运行良好, execute()
返回1
(成功)。 But, when I check the database the value in the status
column hasn't changed. 但是,当我检查数据库时, status
栏中的值没有改变。
/*
* Add jobs to the beanstalkd queue
*/
foreach($jobs as $job) {
$pheanstalk->useTube('scraper')->put(json_encode([
'username' => $job['username'],
'password' => $job['password'],
'proxy' => $job['proxy'],
'gender' => $job['gender'],
'age' => $job['age'],
'device' => $job['device']
]));
/*
* Update the row in the database and change its status to "queued"
*/
try {
$sql = "UPDATE cron_jobs SET status = :status WHERE id = :cid";
$dbh->prepare($sql);
$sth->bindValue(":status", "queued");
$sth->bindValue(":cid", $job['cid']);
print $sth->execute();
} catch(PDOException $e) {
syslog(LOG_ERR, $e->getTraceAsString());
exit;
}
}
Any ideas? 有任何想法吗? It's not reaching the catch
block, and no exceptions occur. 它没有到达catch
块,也没有异常发生。
Maybe you can use commit. 也许您可以使用commit。
$dbh->beginTransaction();
//you code
$dbh->commit();
Check PDO docs. 检查PDO文档。 :) :)
Found the error. 发现错误。 This: 这个:
$dbh->prepare($sql);
Should be: 应该:
$sth = $dbh->prepare($sql);
I had another query in the script above, I often reuse variable names. 我在上面的脚本中有另一个查询,我经常重用变量名。 I totally forgot to add the variable. 我完全忘记添加变量。 It's always the silly mistakes that catch you out the longest. 总是愚蠢的错误会使您最长。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.