Small bugfix to not validate the Slave when it's not enabled

This commit is contained in:
Tiago Peralta 2017-12-10 20:22:58 +00:00
parent 4233563573
commit f290aeee63

View File

@ -6,6 +6,7 @@ class mysqlims extends mysqli
{ {
private $mysqliW; private $mysqliW;
private $mysqliR = null; private $mysqliR = null;
private $slave = false;
/* /*
* Pass main and slave connection arrays to the constructor, and strict as true/false * Pass main and slave connection arrays to the constructor, and strict as true/false
@ -27,6 +28,7 @@ class mysqlims extends mysqli
$this->mysqliR = new mysqli_strict($slave['host'], $this->mysqliR = new mysqli_strict($slave['host'],
$slave['user'], $slave['pass'], $slave['user'], $slave['pass'],
$slave['name'], $slave['port']); $slave['name'], $slave['port']);
$this->slave = true;
} }
} else { } else {
$this->mysqliW = new mysqli($main['host'], $this->mysqliW = new mysqli($main['host'],
@ -37,6 +39,7 @@ class mysqlims extends mysqli
$this->mysqliR = new mysqli($slave['host'], $this->mysqliR = new mysqli($slave['host'],
$slave['user'], $slave['pass'], $slave['user'], $slave['pass'],
$slave['name'], $slave['port']); $slave['name'], $slave['port']);
$this->slave = true;
} }
} }
@ -44,7 +47,7 @@ class mysqlims extends mysqli
throw new Exception("Failed to connect to MySQL: (".$this->mysqliW->connect_errno.") ".$this->mysqliW->connect_error); throw new Exception("Failed to connect to MySQL: (".$this->mysqliW->connect_errno.") ".$this->mysqliW->connect_error);
} }
if ($this->mysqliR->connect_errno) { if ($this->mysqliR->connect_errno && $this->slave === true) {
throw new Exception("Failed to connect to MySQL: (".$this->mysqliR->connect_errno.") ".$this->mysqliR->connect_error); throw new Exception("Failed to connect to MySQL: (".$this->mysqliR->connect_errno.") ".$this->mysqliR->connect_error);
} }
} }