CompleteTrans¶
Complete the transaction, this must be used in conjunction with method StartTrans.
If success returns true, otherwise false.
Example¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <?php
require_once 'dalmp.php';
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$DSN = "utf8://$user:$password".'@127.0.0.1/test';
$db = new DALMP\Database($DSN);
$db->Execute('CREATE TABLE IF NOT EXISTS t_test (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB');
$db->Execute('TRUNCATE TABLE t_test');
$db->FetchMode('ASSOC');
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(1)');
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(2)');
print_r($db->GetAll('SELECT * FROM t_test'));
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(3)');
print_r($db->GetAll('SELECT * FROM t_test'));
$db->StartTrans();
$db->Execute('INSERT INTO t_test VALUES(7)');
print_r($db->GetALL('SELECT * FROM t_test'));
$db->RollBackTrans();
print_r($db->GetALL('SELECT * FROM t_test'));
$db->CompleteTrans();
$db->CompleteTrans();
$db->CompleteTrans();
if ($db->CompleteTrans()) {
// your code
}
|
See also
Thanks Navicat for supporting Open Source projects.
A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.
Donating helps ensure continued support, development and availability.
comments powered by Disqus