-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMysql.php
65 lines (52 loc) · 1.5 KB
/
Mysql.php
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class Freak_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql {
protected $_charset;
protected $_commitStack = array();
/**
* Creates a PDO object and connects to the database.
*
* @return void
* @throws Zend_Db_Adapter_Exception
*/
protected function _connect()
{
if ($this->_connection) {
return;
}
if (!empty($this->_config['charset'])) {
$this->_charset = $this->_config['charset'];
unset($this->_config['charset']);
}
parent::_connect();
if($this->_charset != null) {
$this->_connection->query("SET NAMES '" . $this->_charset . "'");
}
}
public function beginTransaction() {
$count = count($this->_commitStack);
array_push($this->_commitStack, 'ZFsavePoint'.$count);
if($count == 0)
{
parent::beginTransaction();
} else {
$this->query('SAVEPOINT ZFsavePoint'.$count);
}
return $this;
}
public function commit() {
if(count($this->_commitStack) == 1) {
parent::commit();
}
array_pop($this->_commitStack);
return $this;
}
public function rollback() {
$lastTransaction = array_pop($this->_commitStack);
if(count($this->_commitStack == 0)) {
parent::rollback();
} else {
$this->query('ROLLBACK TO SAVEPOINT '.$lastTransaction);
}
return $this;
}
}