Jakub Vrána has uploaded a new change for review.
https://gerrit.wikimedia.org/r/62173
Change subject: Add support for mysqli extension
......................................................................
Add support for mysqli extension
Notice that getType() returns 'mysql'. It means that the database server is
MySQL.
We could introduce a new method returning the used extension but it doesn't
seem necessary.
Bug: 45288
Change-Id: I6733fe21c4aa7443e409c5dfa7c789552b2b62b7
---
M includes/AutoLoader.php
M includes/db/Database.php
M includes/db/DatabaseMysql.php
M includes/db/LoadBalancer.php
M tests/phpunit/MediaWikiTestCase.php
M tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php
6 files changed, 178 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/73/62173/1
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 3fc1d38..921ce96 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -474,6 +474,7 @@
'DatabaseMssql' => 'includes/db/DatabaseMssql.php',
'DatabaseMysql' => 'includes/db/DatabaseMysql.php',
'DatabaseMysqlBase' => 'includes/db/DatabaseMysql.php',
+ 'DatabaseMysqli' => 'includes/db/DatabaseMysql.php',
'DatabaseOracle' => 'includes/db/DatabaseOracle.php',
'DatabasePostgres' => 'includes/db/DatabasePostgres.php',
'DatabaseSqlite' => 'includes/db/DatabaseSqlite.php',
diff --git a/includes/db/Database.php b/includes/db/Database.php
index b315fac..00c0bd9 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -727,7 +727,7 @@
*/
final public static function factory( $dbType, $p = array() ) {
$canonicalDBTypes = array(
- 'mysql', 'postgres', 'sqlite', 'oracle', 'mssql'
+ 'mysql', 'mysqli', 'postgres', 'sqlite', 'oracle',
'mssql'
);
$dbType = strtolower( $dbType );
$class = 'Database' . ucfirst( $dbType );
diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php
index ae3c218..4ab0355 100644
--- a/includes/db/DatabaseMysql.php
+++ b/includes/db/DatabaseMysql.php
@@ -1094,6 +1094,179 @@
/**
+ * Database abstraction object for PHP extension mysqli.
+ *
+ * @ingroup Database
+ * @see Database
+ */
+class DatabaseMysqli extends DatabaseMysqlBase {
+
+ /**
+ * @param $sql string
+ * @return resource
+ */
+ protected function doQuery( $sql ) {
+ if ( $this->bufferResults() ) {
+ $ret = mysqli_query( $this->mConn, $sql );
+ } else {
+ $ret = mysqli_query( $this->mConn, $sql,
MYSQLI_USE_RESULT );
+ }
+ return $ret;
+ }
+
+ protected function mysqlOpen( $realServer ) {
+ # Load mysqli.so if we don't have it
+ wfDl( 'mysqli' );
+
+ # Fail now
+ # Otherwise we get a suppressed fatal error, which is very hard
to track down
+ if ( !function_exists( 'mysqli_connect' ) ) {
+ throw new DBConnectionError( $this, "MySQLi functions
missing, have you compiled PHP with the --with-mysqli option?\n" );
+ }
+
+ $connFlags = 0;
+ if ( $this->mFlags & DBO_SSL ) {
+ $connFlags |= MYSQLI_CLIENT_SSL;
+ }
+ if ( $this->mFlags & DBO_COMPRESS ) {
+ $connFlags |= MYSQLI_CLIENT_COMPRESS;
+ }
+ if ( $this->mFlags & DBO_PERSISTENT ) {
+ if ( version_compare( PHP_VERSION, '5.3.0' ) >= 0 ) {
+ $realServer = 'p:' . $realServer;
+ }
+ }
+
+ $mysqli = mysqli_init();
+ $numAttempts = 2;
+
+ for ( $i = 0; $i < $numAttempts; $i++ ) {
+ if ( $i > 1 ) {
+ usleep( 1000 );
+ }
+ if ( mysqli_real_connect( $mysqli, $realServer,
$this->mUser, $this->mPassword, $this->mDBname, null, null, $connFlags ) ) {
+ return $mysqli;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @return bool
+ */
+ protected function closeConnection() {
+ return mysqli_close( $this->mConn );
+ }
+
+ /**
+ * @return int
+ */
+ function insertId() {
+ return mysqli_insert_id( $this->mConn );
+ }
+
+ /**
+ * @return int
+ */
+ function lastErrno() {
+ if ( $this->mConn ) {
+ return mysqli_errno( $this->mConn );
+ } else {
+ return mysqli_connect_errno();
+ }
+ }
+
+ /**
+ * @return int
+ */
+ function affectedRows() {
+ return mysqli_affected_rows( $this->mConn );
+ }
+
+ /**
+ * @param $db
+ * @return bool
+ */
+ function selectDB( $db ) {
+ $this->mDBname = $db;
+ return mysqli_select_db( $this->mConn, $db );
+ }
+
+ /**
+ * @return string
+ */
+ function getServerVersion() {
+ return mysqli_get_server_info( $this->mConn );
+ }
+
+ protected function mysqlFreeResult( $res ) {
+ mysqli_stmt_free_result( $res );
+ return true;
+ }
+
+ protected function mysqlFetchObject( $res ) {
+ $object = mysqli_fetch_object( $res );
+ if ( $object === null ) {
+ return false;
+ }
+ return $object;
+ }
+
+ protected function mysqlFetchArray( $res ) {
+ $array = mysqli_fetch_array( $res );
+ if ( $array === null ) {
+ return false;
+ }
+ return $array;
+ }
+
+ protected function mysqlNumRows( $res ) {
+ return mysqli_num_rows( $res );
+ }
+
+ protected function mysqlNumFields( $res ) {
+ return mysqli_num_fields( $res );
+ }
+
+ protected function mysqlFetchField( $res, $n ) {
+ $field = mysqli_fetch_field_direct( $res, $n );
+ $field->not_null = $field->flags & MYSQLI_NOT_NULL_FLAG;
+ $field->primary_key = $field->flags & MYSQLI_PRI_KEY_FLAG;
+ $field->unique_key = $field->flags & MYSQLI_UNIQUE_KEY_FLAG;
+ $field->multiple_key = $field->flags & MYSQLI_MULTIPLE_KEY_FLAG;
+ return $field;
+ }
+
+ protected function mysqlFieldName( $res, $n ) {
+ $field = mysqli_fetch_field_direct( $res, $n );
+ return $field->name;
+ }
+
+ protected function mysqlDataSeek( $res, $row ) {
+ return mysqli_data_seek( $res, $row );
+ }
+
+ protected function mysqlError( $conn = null ) {
+ if ($conn === null) {
+ return mysqli_connect_error();
+ } else {
+ return mysqli_error( $conn );
+ }
+ }
+
+ protected function mysqlRealEscapeString( $s ) {
+ return mysqli_real_escape_string( $this->mConn, $s );
+ }
+
+ protected function mysqlPing() {
+ return mysqli_ping( $this->mConn );
+ }
+
+}
+
+
+/**
* Utility class.
* @ingroup Database
*/
diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php
index f702047..44fb1f6 100644
--- a/includes/db/LoadBalancer.php
+++ b/includes/db/LoadBalancer.php
@@ -185,7 +185,7 @@
global $wgReadOnly, $wgDBClusterTimeout, $wgDBAvgStatusPoll,
$wgDBtype;
# @todo FIXME: For now, only go through all this for mysql
databases
- if ( $wgDBtype != 'mysql' ) {
+ if ( strncmp( $wgDBtype, 'mysql', 5 ) != 0 ) {
return $this->getWriterIndex();
}
diff --git a/tests/phpunit/MediaWikiTestCase.php
b/tests/phpunit/MediaWikiTestCase.php
index 440f866..f09c1a0 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -59,6 +59,7 @@
protected $supportedDBs = array(
'mysql',
+ 'mysqli',
'sqlite',
'postgres',
'oracle'
diff --git a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php
b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php
index 3b82e07..e129c37 100644
--- a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php
+++ b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php
@@ -59,7 +59,7 @@
// With MySQL, skips special pages reopening a
temporary table
// See http://bugs.mysql.com/bug.php?id=10327
if (
- $wgDBtype === 'mysql'
+ strncmp( $wgDBtype, 'mysql', 5 ) == 0
&& in_array( $page->getName(),
$this->reopensTempTable )
) {
$this->markTestSkipped( "SQL query for page
{$page->getName()} can not be tested on MySQL backend (it reopens a temporary
table)" );
--
To view, visit https://gerrit.wikimedia.org/r/62173
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6733fe21c4aa7443e409c5dfa7c789552b2b62b7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jakub Vrána <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits