PHP Sqlite3 (not PDO!) transactions?

php, rollback, sqlite, transactions

Solution

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

Problem

Is it possible to use transactions (and rollbacks) with sqlite3 drivers in PHP? I havn't found infos here: https://www.php.net/manual/en/book.sqlite3.php I dont want to use PDO... Thanks for your help

Original source