1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver; |
4
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Driver\Db\ServerInterface; |
6
|
|
|
use Lagdo\DbAdmin\Driver\Entity\UserEntity; |
7
|
|
|
|
8
|
|
|
trait ServerTrait |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var ServerInterface |
12
|
|
|
*/ |
13
|
|
|
protected $server; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get the users and hosts |
17
|
|
|
* |
18
|
|
|
* @param string $database The database name |
19
|
|
|
* |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function getUsers(string $database): array |
23
|
|
|
{ |
24
|
|
|
return $this->server->getUsers($database); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get the grants of a user on a given host |
29
|
|
|
* |
30
|
|
|
* @param string $user The username |
31
|
|
|
* @param string $host The host name |
32
|
|
|
* |
33
|
|
|
* @return UserEntity |
34
|
|
|
*/ |
35
|
|
|
public function getUserGrants(string $user, string $host): UserEntity |
36
|
|
|
{ |
37
|
|
|
return $this->server->getUserGrants($user, $host); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get the user privileges |
42
|
|
|
* |
43
|
|
|
* @param UserEntity $user |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function getUserPrivileges(UserEntity $user) |
48
|
|
|
{ |
49
|
|
|
$this->server->getUserPrivileges($user); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get cached list of databases |
54
|
|
|
* |
55
|
|
|
* @param bool $flush |
56
|
|
|
* |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function databases(bool $flush) |
60
|
|
|
{ |
61
|
|
|
return $this->server->databases($flush); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Compute size of database |
66
|
|
|
* |
67
|
|
|
* @param string $database |
68
|
|
|
* |
69
|
|
|
* @return int |
70
|
|
|
*/ |
71
|
|
|
public function databaseSize(string $database) |
72
|
|
|
{ |
73
|
|
|
return $this->server->databaseSize($database); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get database collation |
78
|
|
|
* |
79
|
|
|
* @param string $database |
80
|
|
|
* @param array $collations |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function databaseCollation(string $database, array $collations) |
85
|
|
|
{ |
86
|
|
|
return $this->server->databaseCollation($database, $collations); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get supported engines |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
public function engines() |
95
|
|
|
{ |
96
|
|
|
return $this->server->engines(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get sorted grouped list of collations |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
public function collations() |
105
|
|
|
{ |
106
|
|
|
return $this->server->collations(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Find out if database is information_schema |
111
|
|
|
* |
112
|
|
|
* @param string $database |
113
|
|
|
* |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function isInformationSchema(string $database) |
117
|
|
|
{ |
118
|
|
|
return $this->server->isInformationSchema($database); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Find out if database is a system database |
123
|
|
|
* |
124
|
|
|
* @param string $database |
125
|
|
|
* |
126
|
|
|
* @return bool |
127
|
|
|
*/ |
128
|
|
|
public function isSystemSchema(string $database) |
129
|
|
|
{ |
130
|
|
|
return $this->server->isSystemSchema($database); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Create a database |
135
|
|
|
* |
136
|
|
|
* @param string $database |
137
|
|
|
* @param string $collation |
138
|
|
|
* |
139
|
|
|
* @return string|boolean |
140
|
|
|
*/ |
141
|
|
|
public function createDatabase(string $database, string $collation) |
142
|
|
|
{ |
143
|
|
|
return $this->server->createDatabase($database, $collation); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Drop a database |
148
|
|
|
* |
149
|
|
|
* @param string $database |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
*/ |
153
|
|
|
public function dropDatabase(string $database) |
154
|
|
|
{ |
155
|
|
|
return $this->server->dropDatabase($database); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Rename database from DB |
160
|
|
|
* |
161
|
|
|
* @param string $name New name |
162
|
|
|
* @param string $collation |
163
|
|
|
* |
164
|
|
|
* @return bool |
165
|
|
|
*/ |
166
|
|
|
public function renameDatabase(string $name, string $collation) |
167
|
|
|
{ |
168
|
|
|
return $this->server->renameDatabase($name, $collation); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get list of available routine languages |
173
|
|
|
* |
174
|
|
|
* @return array |
175
|
|
|
*/ |
176
|
|
|
public function routineLanguages() |
177
|
|
|
{ |
178
|
|
|
return $this->server->routineLanguages(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get server variables |
183
|
|
|
* |
184
|
|
|
* @return array |
185
|
|
|
*/ |
186
|
|
|
public function variables() |
187
|
|
|
{ |
188
|
|
|
return $this->server->variables(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Get status variables |
193
|
|
|
* |
194
|
|
|
* @return array |
195
|
|
|
*/ |
196
|
|
|
public function statusVariables() |
197
|
|
|
{ |
198
|
|
|
return $this->server->statusVariables(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Get process list |
203
|
|
|
* |
204
|
|
|
* @return array |
205
|
|
|
*/ |
206
|
|
|
public function processes() |
207
|
|
|
{ |
208
|
|
|
return $this->server->processes(); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Get a process name |
213
|
|
|
* |
214
|
|
|
* @param array $process |
215
|
|
|
* @param string $key |
216
|
|
|
* @param string $val |
217
|
|
|
* |
218
|
|
|
* @return string |
219
|
|
|
*/ |
220
|
|
|
public function processAttr(array $process, string $key, string $val): string |
221
|
|
|
{ |
222
|
|
|
return $this->server->processAttr($process, $key, $val); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Kill a process |
227
|
|
|
* |
228
|
|
|
* @param int |
229
|
|
|
* |
230
|
|
|
* @return bool |
231
|
|
|
*/ |
232
|
|
|
// public function killProcess($val) |
233
|
|
|
// { |
234
|
|
|
// return $this->server->killProcess($val); |
235
|
|
|
// } |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get maximum number of connections |
239
|
|
|
* |
240
|
|
|
* @return int |
241
|
|
|
*/ |
242
|
|
|
// public function maxConnections() |
243
|
|
|
// { |
244
|
|
|
// return $this->server->maxConnections(); |
245
|
|
|
// } |
246
|
|
|
} |
247
|
|
|
|