return $closed;
}
+ /**
+ * Make sure isOpen() returns true as a sanity check
+ *
+ * @throws DBUnexpectedError
+ */
+ protected function assertOpen() {
+ if ( !$this->isOpen() ) {
+ throw new DBUnexpectedError( $this, "DB connection was already closed." );
+ }
+ }
+
/**
* Closes underlying database connection
* @since 1.20
$queryId = MWDebug::query( $sql, $fname, $isMaster );
# Avoid fatals if close() was called
- if ( !$this->isOpen() ) {
- throw new DBUnexpectedError( $this, "DB connection was already closed." );
- }
+ $this->assertOpen();
# Do the query and handle errors
$startTime = microtime( true );
}
# Avoid fatals if close() was called
- if ( !$this->isOpen() ) {
- throw new DBUnexpectedError( $this, "DB connection was already closed." );
- }
+ $this->assertOpen();
$this->doBegin( $fname );
$this->mTrxTimestamp = microtime( true );
}
# Avoid fatals if close() was called
- if ( !$this->isOpen() ) {
- throw new DBUnexpectedError( $this, "DB connection was already closed." );
- }
+ $this->assertOpen();
$this->runOnTransactionPreCommitCallbacks();
$writeTime = $this->pendingWriteQueryDuration();
}
# Avoid fatals if close() was called
- if ( !$this->isOpen() ) {
- throw new DBUnexpectedError( $this, "DB connection was already closed." );
- }
+ $this->assertOpen();
$this->doRollback( $fname );
$this->mTrxIdleCallbacks = array(); // cancel
function open( $server, $user, $password, $dbName ) {
global $wgAllDBsAreLocalhost, $wgSQLMode;
- # Debugging hack -- fake cluster
- if ( $wgAllDBsAreLocalhost ) {
- $realServer = 'localhost';
- } else {
- $realServer = $server;
- }
+ # Close/unset connection handle
$this->close();
+
+ # Debugging hack -- fake cluster
+ $realServer = $wgAllDBsAreLocalhost ? 'localhost' : $server;
$this->mServer = $server;
$this->mUser = $user;
$this->mPassword = $password;
$this->mDBname = $dbName;
- # The kernel's default SYN retransmission period is far too slow for us,
- # so we use a short timeout plus a manual retry. Retrying means that a small
- # but finite rate of SYN packet loss won't cause user-visible errors.
- $this->mConn = false;
$this->installErrorHandler();
try {
$this->mConn = $this->mysqlConnect( $realServer );