Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class MysqliDb
* @var string
*/
protected $host;
protected $socket;
protected $_username;
protected $_password;
protected $db;
Expand Down Expand Up @@ -226,8 +227,9 @@ class MysqliDb
* @param string $db
* @param int $port
* @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;

Expand All @@ -240,15 +242,18 @@ public function __construct($host = null, $username = null, $password = null, $d
// if host were set as mysqli socket
if (is_object($host)) {
$this->_mysqli = $host;
} else {
$this->host = $host;
}
} else
// in case of using socket & host not exists in config array
if(is_string($host)) {
$this->host = $host;
}

$this->_username = $username;
$this->_password = $password;
$this->db = $db;
$this->port = $port;
$this->charset = $charset;
$this->socket = $socket;

if ($isSubQuery) {
$this->isSubQuery = true;
Expand All @@ -274,11 +279,11 @@ public function connect()
return;
}

if (empty($this->host)) {
throw new Exception('MySQL host is not set');
if (empty($this->host) && empty($this->socket)) {
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) {
throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error, $this->_mysqli->connect_errno);
Expand Down