Merge pull request #1119 from RedKage/patch-1
Support for mysql unix socket
This commit is contained in:
commit
04a4d959fd
|
@ -533,16 +533,29 @@ class Database
|
||||||
*/
|
*/
|
||||||
protected function connect()
|
protected function connect()
|
||||||
{
|
{
|
||||||
|
$isHostUnixSocket = strpos($this->db_host, ':') === 0;
|
||||||
|
|
||||||
// Initizale connection
|
// Initizale connection
|
||||||
try {
|
try {
|
||||||
$this->pdo = new \PDO(
|
if ($isHostUnixSocket) {
|
||||||
'mysql:host=' . $this->db_host .
|
$this->pdo = new \PDO(
|
||||||
';port=' . $this->db_port .
|
'mysql:unix_socket=' . ltrim($this->db_host, ':') .
|
||||||
';dbname=' . $this->db_name .
|
';dbname=' . $this->db_name .
|
||||||
';charset=utf8',
|
';charset=utf8',
|
||||||
$this->db_user,
|
$this->db_user,
|
||||||
$this->db_pass
|
$this->db_pass
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$this->pdo = new \PDO(
|
||||||
|
'mysql:host=' . $this->db_host .
|
||||||
|
';port=' . $this->db_port .
|
||||||
|
';dbname=' . $this->db_name .
|
||||||
|
';charset=utf8',
|
||||||
|
$this->db_user,
|
||||||
|
$this->db_pass
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
$this->status = true;
|
$this->status = true;
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
|
|
Loading…
Reference in New Issue