Lines
0.00%
0 / 11
Functions and Methods
0.00%
0 / 1
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MySQLAccess | 0.00% | 0 / 11 | 0.00% | 0 / 1 | 12 | 0.00% | 0 / 1 | |||
| connect | 0.00% | 0 / 11 | 0.00% | 0 / 1 | 12 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ClientDLDB | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsdldb; | |
| 9 | ||
| 10 | /** | |
| 11 | * | |
| 12 | */ | |
| 13 | class MySQLAccess extends PDOAccess | |
| 14 | { | |
| 15 | protected string $engine = 'MySQL'; | |
| 16 | ||
| 17 | public const string DEFAULT_DATABASE_NAME = 'dldb_frontend_dev'; | |
| 18 | public const string DEFAULT_DATABASE_HOST = 'mariadb'; | |
| 19 | public const int DEFAULT_DATABASE_PORT = 3306; | |
| 20 | public const string DEFAULT_DATABASE_USER = 'root'; | |
| 21 | public const string DEFAULT_DATABASE_PASSWORD = 'password'; | |
| 22 | ||
| 23 | #[\Override] | |
| 24 | protected function connect(array $options): void | |
| 25 | { | |
| 26 | $host = $options['host'] ?? static::DEFAULT_DATABASE_HOST; | |
| 27 | $dbname = $options['database'] ?? static::DEFAULT_DATABASE_NAME; | |
| 28 | $user = $options['user'] ?? static::DEFAULT_DATABASE_USER; | |
| 29 | $pass = $options['password'] ?? static::DEFAULT_DATABASE_PASSWORD; | |
| 30 | $port = $options['port'] ?? static::DEFAULT_DATABASE_PORT; | |
| 31 | if (!$host) { | |
| 32 | $host = 'localhost'; | |
| 33 | } | |
| 34 | ||
| 35 | $dsn = 'mysql:host=' . $host . ';port=' . $port . ';dbname=' . $dbname; | |
| 36 | ||
| 37 | try { | |
| 38 | $this->pdo = new \PDO($dsn, $user, $pass); | |
| 39 | } catch (\Exception $e) { | |
| 40 | throw $e; | |
| 41 | } | |
| 42 | } | |
| 43 | } |