简体   繁体   中英

SQLite3 PHP “Update” -result of prepared query

Does somebody know how i can check in PHP if an SQLite3 update query (prepared) was succesful or not?

Her my code...

$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 );

This code is upodating my table. But "var_dump( $result )" return everytime an empty object. Even if i force an error by passing "rowid=non-existing-rowid".

Any ideas, how i can check my update query?

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM