Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| MariaDatabase | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| connect | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| escapeName | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| escapeLike | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro\Entities\Database; |
| 4 | |
| 5 | use Dynart\Micro\Entities\Database; |
| 6 | |
| 7 | class MariaDatabase extends Database { |
| 8 | |
| 9 | protected function connect(): void { |
| 10 | if ($this->connected()) { |
| 11 | return; |
| 12 | } |
| 13 | $this->pdo = $this->pdoBuilder |
| 14 | ->dsn($this->configValue('dsn')) |
| 15 | ->username($this->configValue('username')) |
| 16 | ->password($this->configValue('password')) |
| 17 | ->options([\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]) |
| 18 | ->build(); |
| 19 | $this->setConnected(true); |
| 20 | $dbName = $this->escapeName($this->configValue('name')); |
| 21 | $this->query("use $dbName"); |
| 22 | $this->query("set names 'utf8'"); |
| 23 | } |
| 24 | |
| 25 | public function escapeName(string $name): string { |
| 26 | $parts = explode('.', $name); |
| 27 | return '`'.join('`.`', $parts).'`'; |
| 28 | } |
| 29 | |
| 30 | public function escapeLike(string $string): string { |
| 31 | return str_replace('%', '\\%', $string); |
| 32 | } |
| 33 | } |