Skip to content

Commit 4c78c1e

Browse files
committed
Transactions
1 parent ad80779 commit 4c78c1e

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

src/DB.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ public function __construct()
4444
$this->mount();
4545
}
4646

47+
public function autoCommit(int $value): DB
48+
{
49+
$statement = sprintf("SET AUTOCOMMIT = %u;", $value);
50+
if (!$this->fire($statement))
51+
{
52+
return false;
53+
}
54+
55+
$this->dump();
56+
57+
return $this;
58+
}
59+
60+
public function begin(): DB
61+
{
62+
$statement = "BEGIN;";
63+
if (!$this->fire($statement))
64+
{
65+
return false;
66+
}
67+
68+
$this->dump();
69+
70+
return $this;
71+
}
72+
4773
protected function buildInsert(array $data, $modifiers=null, $upsert=false): string
4874
{
4975
if ($modifiers)
@@ -167,7 +193,20 @@ protected function buildWhere(): string
167193

168194
return join(' AND ', $tmp);
169195
}
170-
196+
197+
public function commit(): DB
198+
{
199+
$statement = "COMMIT;";
200+
if (!$this->fire($statement))
201+
{
202+
return false;
203+
}
204+
205+
$this->dump();
206+
207+
return $this;
208+
}
209+
171210
public static function config(string $filename)
172211
{
173212
self::$config = $filename;
@@ -470,6 +509,19 @@ public function rightJoin(string $table, string $conditions): DB
470509
return $this;
471510
}
472511

512+
public function rollback(): DB
513+
{
514+
$statement = "ROLLBACK;";
515+
if (!$this->fire($statement))
516+
{
517+
return false;
518+
}
519+
520+
$this->dump();
521+
522+
return $this;
523+
}
524+
473525
public function select(string $value=null): DB
474526
{
475527
$this->select = $value;

0 commit comments

Comments
 (0)