1

如果 SQLite3 更新查询(准备)成功与否,有人知道我如何检查 PHP 吗?

她我的密码...

$stmt = $project->prepare( 'UPDATE tasks set title=:title WHERE rowid=:rowid' );
$stmt->bindValue(':title', rtrim($_POST['title'],'<br>'), SQLITE3_TEXT);
$stmt->bindValue(':rowid', (int)$_POST['rel'], SQLITE3_INTEGER);
$result = $stmt->execute();
var_dump( $result );

这段代码正在更新我的表格。但是“var_dump($result)”每次都会返回一个空对象。即使我通过传递“rowid = non-existing-rowid”来强制出错。

任何想法,我如何检查我的更新查询?

4

1 回答 1

1

An UPDATE statements updates as many record as match the WHERE condition; this could be zero, one, or many records. On the SQL level, all of this is considered a success.

If you want to find out how many records were affected, you can use the changes method of the database connection object. In your case:

...
$result = $stmt->execute();
if ($result) {
    echo 'Updated rows: ', $project->changes();
}
于 2013-07-29T07:13:40.283 回答