* [ADD] Allows to use UNIX socket for MySQL DB connection. Related #382

This commit is contained in:
nuxsmin
2017-01-27 12:06:47 +01:00
parent 013713ebae
commit b4a74a4b6d
4 changed files with 67 additions and 9 deletions

View File

@@ -46,6 +46,10 @@ class MySQLHandler implements DBStorageInterface
* @var string
*/
private $dbHost = '';
/**
* @var string
*/
private $dbSocket;
/**
* @var int
*/
@@ -103,6 +107,7 @@ class MySQLHandler implements DBStorageInterface
$Config = Config::getConfig();
$this->dbHost = $Config->getDbHost();
$this->dbSocket = $Config->getDbSocket();
$this->dbUser = $Config->getDbUser();
$this->dbPass = $Config->getDbPass();
$this->dbName = $Config->getDbName();
@@ -135,7 +140,13 @@ class MySQLHandler implements DBStorageInterface
try {
$opts = [PDO::ATTR_EMULATE_PREPARES => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$dsn = 'mysql:host=' . $this->dbHost . ';port=' . $this->dbPort . ';dbname=' . $this->dbName . ';charset=utf8';
if (empty($this->dbSocket)) {
$dsn = 'mysql:host=' . $this->dbHost . ';port=' . $this->dbPort . ';dbname=' . $this->dbName . ';charset=utf8';
} else {
$dsn = 'mysql:unix_socket=' . $this->dbSocket . ';dbname=' . $this->dbName . ';charset=utf8';
}
$this->db = new PDO($dsn, $this->dbUser, $this->dbPass, $opts);
// $this->db = new PDO($dsn, $this->dbUser, $this->dbPass);
$this->dbStatus = 0;