@@ -136,6 +136,7 @@ class MysqliDb
136136 * @var string
137137 */
138138 protected $ host ;
139+ protected $ socket ;
139140 protected $ _username ;
140141 protected $ _password ;
141142 protected $ db ;
@@ -226,8 +227,9 @@ class MysqliDb
226227 * @param string $db
227228 * @param int $port
228229 * @param string $charset
230+ * @params string $socket
229231 */
230- public function __construct ($ host = null , $ username = null , $ password = null , $ db = null , $ port = null , $ charset = 'utf8 ' )
232+ public function __construct ($ host = null , $ username = null , $ password = null , $ db = null , $ port = null , $ charset = 'utf8 ' , $ socket = null )
231233 {
232234 $ isSubQuery = false ;
233235
@@ -240,15 +242,18 @@ public function __construct($host = null, $username = null, $password = null, $d
240242 // if host were set as mysqli socket
241243 if (is_object ($ host )) {
242244 $ this ->_mysqli = $ host ;
243- } else {
244- $ this ->host = $ host ;
245- }
245+ } else
246+ // in case of using socket & host not exists in config array
247+ if (is_string ($ host )) {
248+ $ this ->host = $ host ;
249+ }
246250
247251 $ this ->_username = $ username ;
248252 $ this ->_password = $ password ;
249253 $ this ->db = $ db ;
250254 $ this ->port = $ port ;
251255 $ this ->charset = $ charset ;
256+ $ this ->socket = $ socket ;
252257
253258 if ($ isSubQuery ) {
254259 $ this ->isSubQuery = true ;
@@ -274,11 +279,11 @@ public function connect()
274279 return ;
275280 }
276281
277- if (empty ($ this ->host )) {
278- throw new Exception ('MySQL host is not set ' );
282+ if (empty ($ this ->host ) && empty ( $ this -> socket ) ) {
283+ throw new Exception ('MySQL host or socket is not set ' );
279284 }
280285
281- $ this ->_mysqli = new mysqli ($ this ->host , $ this ->_username , $ this ->_password , $ this ->db , $ this ->port );
286+ $ this ->_mysqli = new mysqli ($ this ->host , $ this ->_username , $ this ->_password , $ this ->db , $ this ->port , $ this -> socket );
282287
283288 if ($ this ->_mysqli ->connect_error ) {
284289 throw new Exception ('Connect Error ' . $ this ->_mysqli ->connect_errno . ': ' . $ this ->_mysqli ->connect_error , $ this ->_mysqli ->connect_errno );
0 commit comments