Commit ef039a5a authored by Alexander Butenko's avatar Alexander Butenko Committed by GitHub

Merge pull request #627 from ilyagory/master

add socket option to mysqlidb constructor
parents 240a4fd5 8dd1a11a
...@@ -136,6 +136,7 @@ class MysqliDb ...@@ -136,6 +136,7 @@ class MysqliDb
* @var string * @var string
*/ */
protected $host; protected $host;
protected $socket;
protected $_username; protected $_username;
protected $_password; protected $_password;
protected $db; protected $db;
...@@ -226,8 +227,9 @@ class MysqliDb ...@@ -226,8 +227,9 @@ class MysqliDb
* @param string $db * @param string $db
* @param int $port * @param int $port
* @param string $charset * @param string $charset
* @params string $socket
*/ */
public function __construct($host = null, $username = null, $password = null, $db = null, $port = null, $charset = 'utf8') public function __construct($host = null, $username = null, $password = null, $db = null, $port = null, $charset = 'utf8', $socket = null)
{ {
$isSubQuery = false; $isSubQuery = false;
...@@ -240,15 +242,18 @@ class MysqliDb ...@@ -240,15 +242,18 @@ class MysqliDb
// if host were set as mysqli socket // if host were set as mysqli socket
if (is_object($host)) { if (is_object($host)) {
$this->_mysqli = $host; $this->_mysqli = $host;
} else { } else
$this->host = $host; // in case of using socket & host not exists in config array
} if(is_string($host)) {
$this->host = $host;
}
$this->_username = $username; $this->_username = $username;
$this->_password = $password; $this->_password = $password;
$this->db = $db; $this->db = $db;
$this->port = $port; $this->port = $port;
$this->charset = $charset; $this->charset = $charset;
$this->socket = $socket;
if ($isSubQuery) { if ($isSubQuery) {
$this->isSubQuery = true; $this->isSubQuery = true;
...@@ -274,11 +279,11 @@ class MysqliDb ...@@ -274,11 +279,11 @@ class MysqliDb
return; return;
} }
if (empty($this->host)) { if (empty($this->host) && empty($this->socket)) {
throw new Exception('MySQL host is not set'); throw new Exception('MySQL host or socket is not set');
} }
$this->_mysqli = new mysqli($this->host, $this->_username, $this->_password, $this->db, $this->port); $this->_mysqli = new mysqli($this->host, $this->_username, $this->_password, $this->db, $this->port, $this->socket);
if ($this->_mysqli->connect_error) { if ($this->_mysqli->connect_error) {
throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error, $this->_mysqli->connect_errno); throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error, $this->_mysqli->connect_errno);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment