MediaWiki  REL1_22
DatabaseMysql.php
Go to the documentation of this file.
00001 <?php
00030 class DatabaseMysql extends DatabaseMysqlBase {
00031 
00036     protected function doQuery( $sql ) {
00037         if ( $this->bufferResults() ) {
00038             $ret = mysql_query( $sql, $this->mConn );
00039         } else {
00040             $ret = mysql_unbuffered_query( $sql, $this->mConn );
00041         }
00042         return $ret;
00043     }
00044 
00045     protected function mysqlConnect( $realServer ) {
00046         # Fail now
00047         # Otherwise we get a suppressed fatal error, which is very hard to track down
00048         if ( !extension_loaded( 'mysql' ) ) {
00049             throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
00050         }
00051 
00052         $connFlags = 0;
00053         if ( $this->mFlags & DBO_SSL ) {
00054             $connFlags |= MYSQL_CLIENT_SSL;
00055         }
00056         if ( $this->mFlags & DBO_COMPRESS ) {
00057             $connFlags |= MYSQL_CLIENT_COMPRESS;
00058         }
00059 
00060         if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
00061             $numAttempts = 2;
00062         } else {
00063             $numAttempts = 1;
00064         }
00065 
00066         $conn = false;
00067 
00068         for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
00069             if ( $i > 1 ) {
00070                 usleep( 1000 );
00071             }
00072             if ( $this->mFlags & DBO_PERSISTENT ) {
00073                 $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
00074             } else {
00075                 # Create a new connection...
00076                 $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
00077             }
00078         }
00079 
00080         return $conn;
00081     }
00082 
00086     protected function closeConnection() {
00087         return mysql_close( $this->mConn );
00088     }
00089 
00093     function insertId() {
00094         return mysql_insert_id( $this->mConn );
00095     }
00096 
00100     function lastErrno() {
00101         if ( $this->mConn ) {
00102             return mysql_errno( $this->mConn );
00103         } else {
00104             return mysql_errno();
00105         }
00106     }
00107 
00111     function affectedRows() {
00112         return mysql_affected_rows( $this->mConn );
00113     }
00114 
00119     function selectDB( $db ) {
00120         $this->mDBname = $db;
00121         return mysql_select_db( $db, $this->mConn );
00122     }
00123 
00127     function getServerVersion() {
00128         return mysql_get_server_info( $this->mConn );
00129     }
00130 
00131     protected function mysqlFreeResult( $res ) {
00132         return mysql_free_result( $res );
00133     }
00134 
00135     protected function mysqlFetchObject( $res ) {
00136         return mysql_fetch_object( $res );
00137     }
00138 
00139     protected function mysqlFetchArray( $res ) {
00140         return mysql_fetch_array( $res );
00141     }
00142 
00143     protected function mysqlNumRows( $res ) {
00144         return mysql_num_rows( $res );
00145     }
00146 
00147     protected function mysqlNumFields( $res ) {
00148         return mysql_num_fields( $res );
00149     }
00150 
00151     protected function mysqlFetchField( $res, $n ) {
00152         return mysql_fetch_field( $res, $n );
00153     }
00154 
00155     protected function mysqlFieldName( $res, $n ) {
00156         return mysql_field_name( $res, $n );
00157     }
00158 
00159     protected function mysqlDataSeek( $res, $row ) {
00160         return mysql_data_seek( $res, $row );
00161     }
00162 
00163     protected function mysqlError( $conn = null ) {
00164         return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
00165     }
00166 
00167     protected function mysqlRealEscapeString( $s ) {
00168         return mysql_real_escape_string( $s, $this->mConn );
00169     }
00170 
00171     protected function mysqlPing() {
00172         return mysql_ping( $this->mConn );
00173     }
00174 }