return 'mysql';
}
- protected function open( $server, $user, $password, $dbName ) {
+ protected function open( $server, $user, $password, $dbName, $schema, $tablePrefix ) {
# Close/unset connection handle
$this->close();
$this->server = $server;
$this->user = $user;
$this->password = $password;
- $this->dbName = $dbName;
$this->installErrorHandler();
try {
- $this->conn = $this->mysqlConnect( $this->server );
+ $this->conn = $this->mysqlConnect( $this->server, $dbName );
} catch ( Exception $ex ) {
$this->restoreErrorHandler();
throw $ex;
}
if ( strlen( $dbName ) ) {
- Wikimedia\suppressWarnings();
- $success = $this->selectDB( $dbName );
- Wikimedia\restoreWarnings();
- if ( !$success ) {
- $error = $this->lastError();
- $this->queryLogger->error(
- "Error selecting database {db_name} on server {db_server}: {error}",
- $this->getLogContext( [
- 'method' => __METHOD__,
- 'error' => $error,
- ] )
- );
- throw new DBConnectionError( $this, "Error selecting database $dbName: $error" );
- }
+ $this->selectDomain( new DatabaseDomain( $dbName, null, $tablePrefix ) );
+ } else {
+ $this->currentDomain = new DatabaseDomain( null, null, $tablePrefix );
}
// Tell the server what we're communicating with
* Open a connection to a MySQL server
*
* @param string $realServer
+ * @param string|null $dbName
* @return mixed Raw connection
* @throws DBConnectionError
*/
- abstract protected function mysqlConnect( $realServer );
+ abstract protected function mysqlConnect( $realServer, $dbName );
/**
* Set the character set of the MySQL link
$res = $res->result;
}
Wikimedia\suppressWarnings();
- $n = $res ? $this->mysqlNumRows( $res ) : 0;
+ $n = !is_bool( $res ) ? $this->mysqlNumRows( $res ) : 0;
Wikimedia\restoreWarnings();
// Unfortunately, mysql_num_rows does not reset the last errno.
* @param array $uniqueIndexes
* @param array $rows
* @param string $fname
- * @return ResultWrapper
*/
public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
- return $this->nativeReplace( $table, $rows, $fname );
+ $this->nativeReplace( $table, $rows, $fname );
}
protected function isInsertSelectSafe( array $insertOptions, array $selectOptions ) {
// Using one key for all cluster replica DBs is preferable
$this->getLBInfo( 'clusterMasterHost' ) ?: $this->getServer()
);
+ $fname = __METHOD__;
return $cache->getWithSetCallback(
$key,
$cache::TTL_INDEFINITE,
- function () use ( $cache, $key ) {
+ function () use ( $cache, $key, $fname ) {
// Get and leave a lock key in place for a short period
if ( !$cache->lock( $key, 0, 10 ) ) {
return false; // avoid master connection spike slams
// Connect to and query the master; catch errors to avoid outages
try {
- $res = $conn->query( 'SELECT @@server_id AS id', __METHOD__ );
+ $res = $conn->query( 'SELECT @@server_id AS id', $fname );
$row = $res ? $res->fetchObject() : false;
$id = $row ? (int)$row->id : 0;
} catch ( DBError $e ) {
* @throws DBQueryError If the variable doesn't exist for some reason
*/
protected function getServerId() {
+ $fname = __METHOD__;
return $this->srvCache->getWithSetCallback(
$this->srvCache->makeGlobalKey( 'mysql-server-id', $this->getServer() ),
self::SERVER_ID_CACHE_TTL,
- function () {
- $res = $this->query( "SELECT @@server_id AS id", __METHOD__ );
+ function () use ( $fname ) {
+ $res = $this->query( "SELECT @@server_id AS id", $fname );
return intval( $this->fetchObject( $res )->id );
}
);
* @param array|string $conds
* @param bool|string $fname
* @throws DBUnexpectedError
- * @return bool|ResultWrapper
*/
public function deleteJoin(
$delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
$sql .= ' AND ' . $this->makeList( $conds, self::LIST_AND );
}
- return $this->query( $sql, $fname );
+ $this->query( $sql, $fname );
}
/**
$sql .= implode( ',', $rowTuples );
$sql .= " ON DUPLICATE KEY UPDATE " . $this->makeList( $set, self::LIST_SET );
- return (bool)$this->query( $sql, $fname );
+ $this->query( $sql, $fname );
+
+ return true;
}
/**
*/
public function listViews( $prefix = null, $fname = __METHOD__ ) {
// The name of the column containing the name of the VIEW
- $propertyName = 'Tables_in_' . $this->dbName;
+ $propertyName = 'Tables_in_' . $this->getDBname();
// Query for the VIEWS
$res = $this->query( 'SHOW FULL TABLES WHERE TABLE_TYPE = "VIEW"' );