1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graze\DataDb\Adapter; |
4
|
|
|
|
5
|
|
|
use ArrayIterator; |
6
|
|
|
use Graze\DataDb\Dialect\DialectInterface; |
7
|
|
|
use Traversable; |
8
|
|
|
use Zend_Db_Adapter_Abstract; |
9
|
|
|
|
10
|
|
|
class Zend1Adapter implements AdapterInterface |
11
|
|
|
{ |
12
|
|
|
/** @var Zend_Db_Adapter_Abstract */ |
13
|
|
|
private $zendAdapter; |
14
|
|
|
/** @var DialectInterface */ |
15
|
|
|
private $dialect; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Zend1Adapter constructor. |
19
|
|
|
* |
20
|
|
|
* @param Zend_Db_Adapter_Abstract $zendAdapter |
21
|
|
|
* @param DialectInterface $dialect |
22
|
|
|
*/ |
23
|
|
|
public function __construct(Zend_Db_Adapter_Abstract $zendAdapter, DialectInterface $dialect) |
24
|
|
|
{ |
25
|
|
|
$this->zendAdapter = $zendAdapter; |
26
|
|
|
$this->dialect = $dialect; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $sql |
31
|
|
|
* @param array $bind |
32
|
|
|
* |
33
|
|
|
* @return mixed |
34
|
|
|
*/ |
35
|
|
|
public function query($sql, array $bind = []) |
36
|
|
|
{ |
37
|
|
|
return $this->zendAdapter->query($sql, $bind); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $sql |
42
|
|
|
* @param array $bind |
43
|
|
|
* |
44
|
|
|
* @return Traversable |
45
|
|
|
*/ |
46
|
|
|
public function fetch($sql, array $bind = []) |
47
|
|
|
{ |
48
|
|
|
return new ArrayIterator($this->fetchAll($sql, $bind)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $sql |
53
|
|
|
* @param array $bind |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function fetchAll($sql, array $bind = []) |
58
|
|
|
{ |
59
|
|
|
return $this->zendAdapter->fetchAll($sql, $bind); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $sql |
64
|
|
|
* @param array $bind |
65
|
|
|
* |
66
|
|
|
* @return array|bool |
67
|
|
|
*/ |
68
|
|
|
public function fetchRow($sql, array $bind = []) |
69
|
|
|
{ |
70
|
|
|
return $this->zendAdapter->fetchRow($sql, $bind); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $sql |
75
|
|
|
* @param array $bind |
76
|
|
|
* |
77
|
|
|
* @return mixed |
78
|
|
|
*/ |
79
|
|
|
public function fetchOne($sql, array $bind = []) |
80
|
|
|
{ |
81
|
|
|
return $this->zendAdapter->fetchOne($sql, $bind); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param mixed $value |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function quoteValue($value) |
90
|
|
|
{ |
91
|
|
|
return $this->zendAdapter->quoteInto('?', $value); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Start a transaction |
96
|
|
|
* |
97
|
|
|
* @return static |
98
|
|
|
*/ |
99
|
|
|
public function beginTransaction() |
100
|
|
|
{ |
101
|
|
|
$this->zendAdapter->beginTransaction(); |
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return static |
107
|
|
|
*/ |
108
|
|
|
public function commit() |
109
|
|
|
{ |
110
|
|
|
$this->zendAdapter->commit(); |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return static |
116
|
|
|
*/ |
117
|
|
|
public function rollback() |
118
|
|
|
{ |
119
|
|
|
$this->zendAdapter->rollBack(); |
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return DialectInterface |
125
|
|
|
*/ |
126
|
|
|
public function getDialect() |
127
|
|
|
{ |
128
|
|
|
return $this->dialect; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|