Is it possible to use transactions (and rollbacks) with sqlite3 drivers in PHP? I havn't found infos here: http://de2.php.net/manual/en/book.sqlite3.php
I dont want to use PDO...
Thanks for your help
Yes, transactions and rollbacks are possible even without PDO. Astonishing how difficult it is to find an example that explains how to accomplish this. Had to actually dig into some ready code to find out.
$db=new MyDB("database.db", SQLITE3_OPEN_READWRITE);
$db->exec('BEGIN;');
$stmt=$db->prepare('UPDATE table SET name = :name WHERE id = :id');
$stmt->bindValue(':id', $id, SQLITE3_INTEGER);
$stmt->bindValue(':name', $name, SQLITE3_TEXT);
$stmt->execute();
$db->exec('COMMIT;');
Source for logic: sombra2eternity, source for 'MyDB': php.net
Just execute the appropriate SQL commands: BEGIN/COMMIT/ROLLBACK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With