X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseMysqlBase.php;h=e32690947f58840e7e2db9e5b73c0938a62d8772;hb=0bcd8347e597de8d689af1d3c74bb52cafaaf74d;hp=9285d70d3b9a3e9fede1ffcfa0e670bdbf579f24;hpb=359b1b7cbe852640aed7d3c95d682bcb6e9afaa2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseMysqlBase.php b/includes/db/DatabaseMysqlBase.php index 9285d70d3b..e32690947f 100644 --- a/includes/db/DatabaseMysqlBase.php +++ b/includes/db/DatabaseMysqlBase.php @@ -580,9 +580,12 @@ abstract class DatabaseMysqlBase extends DatabaseBase { function ping() { $ping = $this->mysqlPing(); if ( $ping ) { + // Connection was good or lost but reconnected... + // @note: mysqlnd (php 5.6+) does not support this (PHP bug 52561) return true; } + // Try a full disconnect/reconnect cycle if ping() failed $this->closeConnection(); $this->mOpened = false; $this->mConn = false; @@ -1052,6 +1055,28 @@ abstract class DatabaseMysqlBase extends DatabaseBase { ( $this->lastErrno() == 1290 && strpos( $this->lastError(), '--read-only' ) !== false ); } + /** + * Get the underlying binding handle, mConn + * + * Makes sure that mConn is set (disconnects and ping() failure can unset it). + * This catches broken callers than catch and ignore disconnection exceptions. + * Unlike checking isOpen(), this is safe to call inside of open(). + * + * @return resource|object + * @throws DBUnexpectedError + * @since 1.26 + */ + protected function getBindingHandle() { + if ( !$this->mConn ) { + throw new DBUnexpectedError( + $this, + 'DB connection was already closed or the connection dropped.' + ); + } + + return $this->mConn; + } + /** * @param string $oldName * @param string $newName