1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-24 02:43:09 +01:00
php-dibi/examples/using-transactions.php

35 lines
643 B
PHP
Raw Normal View History

2010-08-03 12:28:07 +02:00
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
2010-08-03 11:48:51 +02:00
<h1>Using Transactions | dibi</h1>
2010-08-03 12:28:07 +02:00
2008-07-17 03:51:29 +00:00
<?php
require __DIR__ . '/../dibi/dibi.php';
2008-07-17 03:51:29 +00:00
dibi::connect(array(
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
2008-07-17 03:51:29 +00:00
));
2010-08-03 11:48:51 +02:00
echo "<h2>Before</h2>\n";
2008-07-17 03:51:29 +00:00
dibi::query('SELECT * FROM [products]')->dump();
2008-10-28 02:06:55 +00:00
// -> 3 rows
2008-07-17 03:51:29 +00:00
dibi::begin();
dibi::query('INSERT INTO [products]', array(
'title' => 'Test product',
));
2010-08-03 11:48:51 +02:00
echo "<h2>After INSERT</h2>\n";
dibi::query('SELECT * FROM [products]')->dump();
2008-07-17 03:51:29 +00:00
2010-08-03 11:48:51 +02:00
dibi::rollback(); // or dibi::commit();
echo "<h2>After rollback</h2>\n";
2008-10-28 02:06:55 +00:00
dibi::query('SELECT * FROM [products]')->dump();
2010-08-03 11:48:51 +02:00
// -> 3 rows again