Commit 81f4a950 authored by Tim Schoondergang's avatar Tim Schoondergang

Merge branch '15-mysqli_ping-insteat-of-link-2' into 'master'

Resolve "mysqli_ping insteat of (!$link)"

Closes #15

See merge request !27
parents a35f64cd 58d960dd
{
"name": "timmit/db-mysql",
"description": "A simple DB layer in PHP for using MySQL(i)",
"version": "v4.0.3",
"version": "v4.0.4",
"keywords": ["DB", "MySQL", "MySQLi", "database", "DB layer", "database layer"],
"license": "MIT",
"homepage": "http://www.TiMMiT.nl/",
......
......@@ -162,10 +162,10 @@ namespace TiMMiT\MySQL;
mysqli_report(MYSQLI_REPORT_OFF); // back to normal reporting
if (self::$mlink) {
if (mysqli_ping(self::$mlink)) {
mysqli_set_charset(self::$mlink,self::$charset);
}
if (self::$writeActive && self::$mlinkWrite) {
if (self::$writeActive && mysqli_ping(self::$mlinkWrite)) {
mysqli_set_charset(self::$mlinkWrite,self::$charset);
mysqli_query(self::$mlink,"SET SESSION wsrep_sync_wait = 1;");
}
......@@ -177,13 +177,12 @@ namespace TiMMiT\MySQL;
*/
public static function disconnect() {
self::addToStats(__FUNCTION__);
if(self::$mlink){
if (self::$writeActive && self::$mlinkWrite) {
mysqli_close(self::$mlinkWrite);
}
return mysqli_close(self::$mlink);
if (self::$writeActive && mysqli_ping(self::$mlinkWrite)) {
mysqli_close(self::$mlinkWrite);
}
if(mysqli_ping(self::$mlink)){
mysqli_close(self::$mlink);
}
return true;
}
/**
......@@ -202,10 +201,10 @@ namespace TiMMiT\MySQL;
* @param boolean $writeQuery
* @param int $resultmode
* @param int $count
* @return boolean
* @return \mysqli_result|boolean
*/
private static function query($query,$writeQuery=false,$resultmode=NULL,$count=0) {
if ($writeQuery && self::$writeActive && self::$mlinkWrite) {
if ($writeQuery && self::$writeActive && mysqli_ping(self::$mlinkWrite)) {
$write = true;
} else {
$write = false;
......@@ -244,11 +243,7 @@ namespace TiMMiT\MySQL;
case 2006:
case 1047:
if($count < self::$max_goneaway_count){
if($write){
mysqli_close(self::$mlinkWrite);
} else {
mysqli_close(self::$mlink);
}
self::disconnect();
$count++;
usleep(($count*round(100000,1000000)*self::$sleep_goneaway_multiplier));
self::reconnect();
......@@ -530,11 +525,10 @@ namespace TiMMiT\MySQL;
return $where;
}
/**
* dbDelta on DB
* @param string $queries
* @param boolean $execute
*
* @return array
*/
public static function dbDelta( $queries = '', $execute = true ) {
......
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