Move up devunt's name to Developers
[lhc/web/wiklou.git] / includes / db / DatabaseMysqli.php
index 8c9b06c..d2b5ecb 100644 (file)
@@ -58,14 +58,22 @@ class DatabaseMysqli extends DatabaseMysqlBase {
                }
 
                // Other than mysql_connect, mysqli_real_connect expects an explicit port
-               // parameter. So we need to parse the port out of $realServer
+               // and socket parameters. So we need to parse the port and socket out of
+               // $realServer
                $port = null;
+               $socket = null;
                $hostAndPort = IP::splitHostAndPort( $realServer );
                if ( $hostAndPort ) {
                        $realServer = $hostAndPort[0];
                        if ( $hostAndPort[1] ) {
                                $port = $hostAndPort[1];
                        }
+               } elseif ( substr_count( $realServer, ':' ) == 1 ) {
+                       // If we have a colon and something that's not a port number
+                       // inside the hostname, assume it's the socket location
+                       $hostAndSocket = explode( ':', $realServer );
+                       $realServer = $hostAndSocket[0];
+                       $socket = $hostAndSocket[1];
                }
 
                $connFlags = 0;
@@ -87,17 +95,12 @@ class DatabaseMysqli extends DatabaseMysqlBase {
                } else {
                        $mysqli->options( MYSQLI_SET_CHARSET_NAME, 'binary' );
                }
+               $mysqli->options( MYSQLI_OPT_CONNECT_TIMEOUT, 3 );
 
-               $numAttempts = 2;
-               for ( $i = 0; $i < $numAttempts; $i++ ) {
-                       if ( $i > 1 ) {
-                               usleep( 1000 );
-                       }
-                       if ( $mysqli->real_connect( $realServer, $this->mUser,
-                               $this->mPassword, $this->mDBname, $port, null, $connFlags )
-                       ) {
-                               return $mysqli;
-                       }
+               if ( $mysqli->real_connect( $realServer, $this->mUser,
+                       $this->mPassword, $this->mDBname, $port, $socket, $connFlags )
+               ) {
+                       return $mysqli;
                }
 
                return false;
@@ -131,7 +134,7 @@ class DatabaseMysqli extends DatabaseMysqlBase {
         * @return int
         */
        function insertId() {
-               return $this->mConn->insert_id;
+               return (int)$this->mConn->insert_id;
        }
 
        /**
@@ -162,13 +165,6 @@ class DatabaseMysqli extends DatabaseMysqlBase {
                return $this->mConn->select_db( $db );
        }
 
-       /**
-        * @return string
-        */
-       function getServerVersion() {
-               return $this->mConn->server_info;
-       }
-
        /**
         * @param mysqli $res
         * @return bool
@@ -228,11 +224,18 @@ class DatabaseMysqli extends DatabaseMysqlBase {
         */
        protected function mysqlFetchField( $res, $n ) {
                $field = $res->fetch_field_direct( $n );
+
+               // Add missing properties to result (using flags property)
+               // which will be part of function mysql-fetch-field for backward compatibility
                $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;
                $field->binary = $field->flags & MYSQLI_BINARY_FLAG;
+               $field->numeric = $field->flags & MYSQLI_NUM_FLAG;
+               $field->blob = $field->flags & MYSQLI_BLOB_FLAG;
+               $field->unsigned = $field->flags & MYSQLI_UNSIGNED_FLAG;
+               $field->zerofill = $field->flags & MYSQLI_ZEROFILL_FLAG;
 
                return $field;
        }
@@ -297,6 +300,7 @@ class DatabaseMysqli extends DatabaseMysqlBase {
         * Give an id for the connection
         *
         * mysql driver used resource id, but mysqli objects cannot be cast to string.
+        * @return string
         */
        public function __toString() {
                if ( $this->mConn instanceof Mysqli ) {