/**
* This is the MySQL database abstraction layer.
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
* @ingroup Database
*/
$phpError = $this->restoreErrorHandler();
# Always log connection errors
if ( !$this->mConn ) {
- $error = $this->lastError();
+ $error = $phpError;
if ( !$error ) {
- $error = $phpError;
+ $error = $this->lastError();
}
wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
wfDebug( "DB connection error\n" );
wfDebug( "Server: $server, User: $user, Password: " .
- substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" );
+ substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
}
wfProfileOut("dbconnect-$server");
/**
* @return bool
*/
- function close() {
- $this->mOpened = false;
- if ( $this->mConn ) {
- if ( $this->trxLevel() ) {
- $this->commit();
- }
- return mysql_close( $this->mConn );
- } else {
- return true;
- }
+ protected function closeConnection() {
+ return mysql_close( $this->mConn );
}
/**
* @param $table string
* @param $index string
* @param $fname string
- * @return false|array
+ * @return bool|array|null False or null on failure
*/
function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) {
# SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
# Commit any open transactions
if ( $this->mTrxLevel ) {
- $this->commit();
+ $this->commit( __METHOD__ );
}
if ( !is_null( $this->mFakeSlaveLag ) ) {
/**
* Get the position of the master from SHOW SLAVE STATUS
*
- * @return MySQLMasterPos|false
+ * @return MySQLMasterPos|bool
*/
function getSlavePos() {
if ( !is_null( $this->mFakeSlaveLag ) ) {
/**
* Get the position of the master from SHOW MASTER STATUS
*
- * @return MySQLMasterPos|false
+ * @return MySQLMasterPos|bool
*/
function getMasterPos() {
if ( $this->mFakeMaster ) {
return parent::streamStatementEnd( $sql, $newLine );
}
+ /**
+ * Check to see if a named lock is available. This is non-blocking.
+ *
+ * @param $lockName String: name of lock to poll
+ * @param $method String: name of method calling us
+ * @return Boolean
+ * @since 1.20
+ */
+ public function lockIsFree( $lockName, $method ) {
+ $lockName = $this->addQuotes( $lockName );
+ $result = $this->query( "SELECT IS_FREE_LOCK($lockName) AS lockstatus", $method );
+ $row = $this->fetchObject( $result );
+ return ( $row->lockstatus == 1 );
+ }
+
/**
* @param $lockName string
* @param $method string
$lockName = $this->addQuotes( $lockName );
$result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
$row = $this->fetchObject( $result );
- return $row->lockstatus;
+ return ( $row->lockstatus == 1 );
}
/**
/**
* List all tables on the database
*
- * @param $prefix Only show tables with this prefix, e.g. mw_
+ * @param $prefix string Only show tables with this prefix, e.g. mw_
* @param $fname String: calling function name
* @return array
*/