|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class Database |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource Database.php |
|
6
|
|
|
* @created 27.06.2017 |
|
7
|
|
|
* @package chillerlan\Database |
|
8
|
|
|
* @author Smiley <[email protected]> |
|
9
|
|
|
* @copyright 2017 Smiley |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace chillerlan\Database; |
|
14
|
|
|
|
|
15
|
|
|
use chillerlan\Database\{ |
|
16
|
|
|
Dialects\Dialect, Drivers\DriverInterface, Query\QueryBuilder |
|
17
|
|
|
}; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @property \chillerlan\Database\Query\Alter $alter |
|
21
|
|
|
* @property \chillerlan\Database\Query\Create $create |
|
22
|
|
|
* @property \chillerlan\Database\Query\Delete $delete |
|
23
|
|
|
* @property \chillerlan\Database\Query\Drop $drop |
|
24
|
|
|
* @property \chillerlan\Database\Query\Insert $insert |
|
25
|
|
|
* @property \chillerlan\Database\Query\Select $select |
|
26
|
|
|
* @property \chillerlan\Database\Query\Show $show |
|
27
|
|
|
* @property \chillerlan\Database\Query\Truncate $truncate |
|
28
|
|
|
* @property \chillerlan\Database\Query\Update $update |
|
29
|
|
|
*/ |
|
30
|
|
|
class Database extends DatabaseAbstract implements DriverInterface{ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
* @codeCoverageIgnore |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __destruct(){ |
|
37
|
|
|
$this->driver->disconnect(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** @inheritdoc */ |
|
41
|
|
|
public function __get(string $name){ |
|
42
|
|
|
return $this->query->{$name}; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return \chillerlan\Database\Drivers\DriverInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getDriver():DriverInterface{ |
|
49
|
|
|
return $this->driver; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return \chillerlan\Database\Query\QueryBuilder |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getQueryBuilder():QueryBuilder{ |
|
56
|
|
|
return $this->query; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @inheritdoc |
|
61
|
|
|
* @codeCoverageIgnore |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getDBResource(){ |
|
64
|
|
|
return $this->driver->getDBResource(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** @inheritdoc */ |
|
68
|
|
|
public function connect():DriverInterface{ |
|
69
|
|
|
$this->driver->connect(); |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** @inheritdoc */ |
|
75
|
|
|
public function disconnect():bool{ |
|
76
|
|
|
return $this->driver->disconnect(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** @inheritdoc */ |
|
80
|
|
|
public function getClientInfo():string{ |
|
81
|
|
|
return $this->driver->getClientInfo(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** @inheritdoc */ |
|
85
|
|
|
public function getServerInfo():string{ |
|
86
|
|
|
return $this->driver->getServerInfo(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** @inheritdoc */ |
|
90
|
|
|
public function escape($data = null){ |
|
91
|
|
|
return $this->driver->escape($data); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** @inheritdoc */ |
|
95
|
|
|
public function raw(string $sql, string $index = null, bool $assoc = null){ |
|
96
|
|
|
return $this->driver->raw($sql, $index, $assoc); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** @inheritdoc */ |
|
100
|
|
|
public function rawCached(string $sql, string $index = null, bool $assoc = null, int $ttl = null){ |
|
101
|
|
|
return $this->driver->rawCached($sql, $index, $assoc, $ttl); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** @inheritdoc */ |
|
105
|
|
|
public function prepared(string $sql, array $values = null, string $index = null, bool $assoc = null){ |
|
106
|
|
|
return $this->driver->prepared($sql, $values, $index, $assoc); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** @inheritdoc */ |
|
110
|
|
|
public function preparedCached(string $sql, array $values = null, string $index = null, bool $assoc = null, int $ttl = null){ |
|
111
|
|
|
return $this->driver->preparedCached($sql, $values, $index, $assoc, $ttl); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** @inheritdoc */ |
|
115
|
|
|
public function multi(string $sql, array $values){ |
|
116
|
|
|
return $this->driver->multi($sql, $values); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** @inheritdoc */ |
|
120
|
|
|
public function multiCallback(string $sql, iterable $data, $callback){ |
|
121
|
|
|
return $this->driver->multiCallback($sql, $data, $callback); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** @inheritdoc */ |
|
125
|
|
|
public function getDialect():Dialect{ |
|
126
|
|
|
return $this->driver->getDialect(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|