X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Fdatabase%2FDatabaseMysqli.php;h=1c4ed56d40d22228da7439b26e33a96b4f8f9aa2;hb=73f29466c496d8a3f3f0eddd5320a567ab0a6125;hp=6d9dabd80388fe12d5a4a03ee8777ead4d17604c;hpb=5410cfccce9b0b84bc909506c9b66d3f27d6dba7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/database/DatabaseMysqli.php b/includes/libs/rdbms/database/DatabaseMysqli.php index 6d9dabd803..1c4ed56d40 100644 --- a/includes/libs/rdbms/database/DatabaseMysqli.php +++ b/includes/libs/rdbms/database/DatabaseMysqli.php @@ -37,7 +37,7 @@ use stdClass; class DatabaseMysqli extends DatabaseMysqlBase { /** * @param string $sql - * @return mysqli_result + * @return mysqli_result|bool */ protected function doQuery( $sql ) { $conn = $this->getBindingHandle(); @@ -53,10 +53,11 @@ class DatabaseMysqli extends DatabaseMysqlBase { /** * @param string $realServer + * @param string|null $dbName * @return bool|mysqli * @throws DBConnectionError */ - protected function mysqlConnect( $realServer ) { + protected function mysqlConnect( $realServer, $dbName ) { # Avoid suppressed fatal error, which is very hard to track down if ( !function_exists( 'mysqli_init' ) ) { throw new DBConnectionError( $this, "MySQLi functions missing," @@ -111,9 +112,15 @@ class DatabaseMysqli extends DatabaseMysqlBase { } $mysqli->options( MYSQLI_OPT_CONNECT_TIMEOUT, 3 ); - if ( $mysqli->real_connect( $realServer, $this->user, - $this->password, $this->dbName, $port, $socket, $connFlags ) - ) { + if ( $mysqli->real_connect( + $realServer, + $this->user, + $this->password, + $dbName, + $port, + $socket, + $connFlags + ) ) { return $mysqli; } @@ -132,11 +139,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { protected function mysqlSetCharset( $charset ) { $conn = $this->getBindingHandle(); - if ( method_exists( $conn, 'set_charset' ) ) { - return $conn->set_charset( $charset ); - } else { - return $this->query( 'SET NAMES ' . $charset, __METHOD__ ); - } + return $conn->set_charset( $charset ); } /** @@ -177,16 +180,23 @@ class DatabaseMysqli extends DatabaseMysqlBase { return $conn->affected_rows; } - /** - * @param string $db - * @return bool - */ - function selectDB( $db ) { - $conn = $this->getBindingHandle(); + function doSelectDomain( DatabaseDomain $domain ) { + if ( $domain->getSchema() !== null ) { + throw new DBExpectedError( $this, __CLASS__ . ": domain schemas are not supported." ); + } - $this->dbName = $db; + $database = $domain->getDatabase(); + if ( $database !== $this->getDBname() ) { + $conn = $this->getBindingHandle(); + if ( !$conn->select_db( $database ) ) { + throw new DBExpectedError( $this, "Could not select database '$database'." ); + } + } - return $conn->select_db( $db ); + // Update that domain fields on success (no exception thrown) + $this->currentDomain = $domain; + + return true; } /**