| Total Complexity | 10 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 83.33% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Driver extends AbstractMySQLDriver |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * {@inheritdoc} |
||
| 17 | */ |
||
| 18 | 318 | public function connect(array $params, $username = null, $password = null, array $driverOptions = []) |
|
| 19 | { |
||
| 20 | try { |
||
| 21 | 318 | $conn = new PDOConnection( |
|
| 22 | 318 | $this->constructPdoDsn($params), |
|
| 23 | $username, |
||
| 24 | $password, |
||
| 25 | $driverOptions |
||
| 26 | ); |
||
| 27 | 213 | } catch (PDOException $e) { |
|
| 28 | 213 | throw DBALException::driverException($this, $e); |
|
| 29 | } |
||
| 30 | |||
| 31 | 318 | return $conn; |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Constructs the MySql PDO DSN. |
||
| 36 | * |
||
| 37 | * @param mixed[] $params |
||
| 38 | * |
||
| 39 | * @return string The DSN. |
||
| 40 | */ |
||
| 41 | 318 | protected function constructPdoDsn(array $params) |
|
| 42 | { |
||
| 43 | 318 | $dsn = 'mysql:'; |
|
| 44 | 318 | if (isset($params['host']) && $params['host'] !== '') { |
|
| 45 | 318 | $dsn .= 'host=' . $params['host'] . ';'; |
|
| 46 | } |
||
| 47 | 318 | if (isset($params['port'])) { |
|
| 48 | 318 | $dsn .= 'port=' . $params['port'] . ';'; |
|
| 49 | } |
||
| 50 | 318 | if (isset($params['dbname'])) { |
|
| 51 | 318 | $dsn .= 'dbname=' . $params['dbname'] . ';'; |
|
| 52 | } |
||
| 53 | 318 | if (isset($params['unix_socket'])) { |
|
| 54 | $dsn .= 'unix_socket=' . $params['unix_socket'] . ';'; |
||
| 55 | } |
||
| 56 | 318 | if (isset($params['charset'])) { |
|
| 57 | 136 | $dsn .= 'charset=' . $params['charset'] . ';'; |
|
| 58 | } |
||
| 59 | |||
| 60 | 318 | return $dsn; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 329 | public function getName() |
|
| 69 | } |
||
| 70 | } |
||
| 71 |