如何判断何时在PHP PDO中成功执行查询? [英] How to tell when query executed successfully in PHP PDO?
本文介绍了如何判断何时在PHP PDO中成功执行查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何测试以下查询是否成功执行?
How can I test to see if the following query executed successfully?
$STH = $this->_db->prepare("UPDATE UserCreds SET
VerificationString=:newVerificationString, ExpiryDate=:expiryDate
WHERE UserID = :userID;");
$STH->execute($params);
我知道添加新行时可以使用lastInsertId()
,但是UPDATE和SELECT呢?
I know I can use lastInsertId()
when I'm adding new rows, but what about UPDATEs and SELECTs?
推荐答案
execute
成功返回true
,失败返回false
.
The execute
returns true
on success and false
on failure.
成功返回TRUE,失败返回FALSE.
Returns TRUE on success or FALSE on failure.
因此,您可以确保查询成功运行,如:
So you can make sure query ran successfully like:
if ($STH->execute($params))
{
// success
}
else
{
// failure
}
这篇关于如何判断何时在PHP PDO中成功执行查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文