1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver; |
4
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Driver\Entity\TableFieldEntity; |
6
|
|
|
use Lagdo\DbAdmin\Driver\Db\StatementInterface; |
7
|
|
|
|
8
|
|
|
trait ConnectionTrait |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Get the server description |
12
|
|
|
* |
13
|
|
|
* @return string |
14
|
|
|
*/ |
15
|
|
|
public function serverInfo() |
16
|
|
|
{ |
17
|
|
|
return $this->connection->serverInfo(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get the driver extension |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function extension() |
26
|
|
|
{ |
27
|
|
|
return $this->connection->extension(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Sets the client character set |
32
|
|
|
* |
33
|
|
|
* @param string $charset |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function setCharset(string $charset) |
38
|
|
|
{ |
39
|
|
|
$this->connection->setCharset($charset); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Return a quoted string |
44
|
|
|
* |
45
|
|
|
* @param string $string |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function quote(string $string) |
50
|
|
|
{ |
51
|
|
|
return $this->connection->quote($string); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Return a quoted string |
56
|
|
|
* |
57
|
|
|
* @param string $string |
58
|
|
|
* |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
|
|
public function quoteBinary(string $string) |
62
|
|
|
{ |
63
|
|
|
return $this->connection->quoteBinary($string); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Execute a query on the current database |
68
|
|
|
* |
69
|
|
|
* @param string $query |
70
|
|
|
* @param bool $unbuffered |
71
|
|
|
* |
72
|
|
|
* @return StatementInterface|bool |
73
|
|
|
*/ |
74
|
|
|
public function query(string $query, bool $unbuffered = false) |
75
|
|
|
{ |
76
|
|
|
return $this->connection->query($query, $unbuffered); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the number of rows affected by the last query |
81
|
|
|
* |
82
|
|
|
* @return integer |
83
|
|
|
*/ |
84
|
|
|
public function affectedRows() |
85
|
|
|
{ |
86
|
|
|
return $this->connection->affectedRows(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Execute a query on the current database and fetch the specified field |
91
|
|
|
* |
92
|
|
|
* @param string $query |
93
|
|
|
* @param int $field |
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function result(string $query, int $field = -1) |
98
|
|
|
{ |
99
|
|
|
return $this->connection->result($query, $field); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Execute a query on the current database and store the result |
104
|
|
|
* |
105
|
|
|
* @param string $query |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
public function multiQuery(string $query) |
110
|
|
|
{ |
111
|
|
|
return $this->connection->multiQuery($query); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the result saved by the multiQuery() method |
116
|
|
|
* |
117
|
|
|
* @return StatementInterface|bool |
118
|
|
|
*/ |
119
|
|
|
public function storedResult() |
120
|
|
|
{ |
121
|
|
|
return $this->connection->storedResult(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get the next row set of the last query |
126
|
|
|
* |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
public function nextResult() |
130
|
|
|
{ |
131
|
|
|
return $this->connection->nextResult(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Convert value returned by database to actual value |
136
|
|
|
* |
137
|
|
|
* @param string|resource|null $value |
138
|
|
|
* @param TableFieldEntity $field |
139
|
|
|
* |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public function value($value, TableFieldEntity $field) |
143
|
|
|
{ |
144
|
|
|
return $this->connection->value($value, $field); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|