我正在使用 PDO 和 MySQL 编写一些代码,并且需要非常确定是否UPDATE
成功。
我希望更新 1 行,并且我正在使用 PDO 的rowCount()
方法来检查返回值 1。如果 1 或 0 行受到影响(“更新”或“未更新”),我知道该怎么做。
这会以任何方式出错吗?例如,如果查询执行失败,它会返回什么?如果数据库以某种方式损坏或崩溃怎么办?
If the query fails execute will return false. If it succeed than returned value will be affected row count. It can be >=0. Don't use rowCount for checking if update did occured or no because it should always return one row, unless query failed (due to error)
sqrt(-1) loves php
In a properly written application it just never gets executed - an exception is fired and handler just kills the whole script.