| @@ 92-116 (lines=25) @@ | ||
| 89 | * @return \PDO the database resource object |
|
| 90 | * @throws \chillerlan\Database\DBException |
|
| 91 | */ |
|
| 92 | public function connect():PDO { |
|
| 93 | ||
| 94 | if($this->db instanceof PDO){ |
|
| 95 | return $this->db; |
|
| 96 | } |
|
| 97 | ||
| 98 | if($this->options->use_ssl){ |
|
| 99 | $this->pdo_options += [ |
|
| 100 | PDO::MYSQL_ATTR_SSL_KEY => $this->options->ssl_key, |
|
| 101 | PDO::MYSQL_ATTR_SSL_CERT => $this->options->ssl_cert, |
|
| 102 | PDO::MYSQL_ATTR_SSL_CA => $this->options->ssl_ca, |
|
| 103 | PDO::MYSQL_ATTR_SSL_CAPATH => $this->options->ssl_capath, |
|
| 104 | PDO::MYSQL_ATTR_SSL_CIPHER => $this->options->ssl_cipher, |
|
| 105 | ]; |
|
| 106 | } |
|
| 107 | ||
| 108 | try{ |
|
| 109 | $this->db = new PDO($this->getDSN(), $this->options->username, $this->options->password, $this->pdo_options); |
|
| 110 | } |
|
| 111 | catch(PDOException $PDOException){ |
|
| 112 | throw new DBException($PDOException->getMessage()); |
|
| 113 | } |
|
| 114 | ||
| 115 | return $this->db; |
|
| 116 | } |
|
| 117 | ||
| 118 | /** |
|
| 119 | * Closes a database connection |
|
| @@ 96-120 (lines=25) @@ | ||
| 93 | * @return \chillerlan\Database\Drivers\DBDriverInterface |
|
| 94 | * @throws \chillerlan\Database\DBException |
|
| 95 | */ |
|
| 96 | public function connect():DBDriverInterface{ |
|
| 97 | ||
| 98 | if($this->db instanceof PDO){ |
|
| 99 | return $this; |
|
| 100 | } |
|
| 101 | ||
| 102 | if($this->options->use_ssl){ |
|
| 103 | $this->pdo_options += [ |
|
| 104 | PDO::MYSQL_ATTR_SSL_KEY => $this->options->ssl_key, |
|
| 105 | PDO::MYSQL_ATTR_SSL_CERT => $this->options->ssl_cert, |
|
| 106 | PDO::MYSQL_ATTR_SSL_CA => $this->options->ssl_ca, |
|
| 107 | PDO::MYSQL_ATTR_SSL_CAPATH => $this->options->ssl_capath, |
|
| 108 | PDO::MYSQL_ATTR_SSL_CIPHER => $this->options->ssl_cipher, |
|
| 109 | ]; |
|
| 110 | } |
|
| 111 | ||
| 112 | try{ |
|
| 113 | $this->db = new PDO($this->getDSN(), $this->options->username, $this->options->password, $this->pdo_options); |
|
| 114 | } |
|
| 115 | catch(PDOException $PDOException){ |
|
| 116 | throw new DBException($PDOException->getMessage()); |
|
| 117 | } |
|
| 118 | ||
| 119 | return $this; |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * Closes a database connection |
|