MediaWiki  REL1_24
DatabaseMysql.php
Go to the documentation of this file.
00001 <?php
00030 class DatabaseMysql extends DatabaseMysqlBase {
00035     protected function doQuery( $sql ) {
00036         if ( $this->bufferResults() ) {
00037             $ret = mysql_query( $sql, $this->mConn );
00038         } else {
00039             $ret = mysql_unbuffered_query( $sql, $this->mConn );
00040         }
00041 
00042         return $ret;
00043     }
00044 
00050     protected function mysqlConnect( $realServer ) {
00051         # Fail now
00052         # Otherwise we get a suppressed fatal error, which is very hard to track down
00053         if ( !extension_loaded( 'mysql' ) ) {
00054             throw new DBConnectionError(
00055                 $this,
00056                 "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n"
00057             );
00058         }
00059 
00060         $connFlags = 0;
00061         if ( $this->mFlags & DBO_SSL ) {
00062             $connFlags |= MYSQL_CLIENT_SSL;
00063         }
00064         if ( $this->mFlags & DBO_COMPRESS ) {
00065             $connFlags |= MYSQL_CLIENT_COMPRESS;
00066         }
00067 
00068         if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
00069             $numAttempts = 2;
00070         } else {
00071             $numAttempts = 1;
00072         }
00073 
00074         $conn = false;
00075 
00076         for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
00077             if ( $i > 1 ) {
00078                 usleep( 1000 );
00079             }
00080             if ( $this->mFlags & DBO_PERSISTENT ) {
00081                 $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
00082             } else {
00083                 # Create a new connection...
00084                 $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
00085             }
00086         }
00087 
00088         return $conn;
00089     }
00090 
00095     protected function mysqlSetCharset( $charset ) {
00096         if ( function_exists( 'mysql_set_charset' ) ) {
00097             return mysql_set_charset( $charset, $this->mConn );
00098         } else {
00099             return $this->query( 'SET NAMES ' . $charset, __METHOD__ );
00100         }
00101     }
00102 
00106     protected function closeConnection() {
00107         return mysql_close( $this->mConn );
00108     }
00109 
00113     function insertId() {
00114         return mysql_insert_id( $this->mConn );
00115     }
00116 
00120     function lastErrno() {
00121         if ( $this->mConn ) {
00122             return mysql_errno( $this->mConn );
00123         } else {
00124             return mysql_errno();
00125         }
00126     }
00127 
00131     function affectedRows() {
00132         return mysql_affected_rows( $this->mConn );
00133     }
00134 
00139     function selectDB( $db ) {
00140         $this->mDBname = $db;
00141 
00142         return mysql_select_db( $db, $this->mConn );
00143     }
00144 
00148     function getServerVersion() {
00149         return mysql_get_server_info( $this->mConn );
00150     }
00151 
00152     protected function mysqlFreeResult( $res ) {
00153         return mysql_free_result( $res );
00154     }
00155 
00156     protected function mysqlFetchObject( $res ) {
00157         return mysql_fetch_object( $res );
00158     }
00159 
00160     protected function mysqlFetchArray( $res ) {
00161         return mysql_fetch_array( $res );
00162     }
00163 
00164     protected function mysqlNumRows( $res ) {
00165         return mysql_num_rows( $res );
00166     }
00167 
00168     protected function mysqlNumFields( $res ) {
00169         return mysql_num_fields( $res );
00170     }
00171 
00172     protected function mysqlFetchField( $res, $n ) {
00173         return mysql_fetch_field( $res, $n );
00174     }
00175 
00176     protected function mysqlFieldName( $res, $n ) {
00177         return mysql_field_name( $res, $n );
00178     }
00179 
00180     protected function mysqlFieldType( $res, $n ) {
00181         return mysql_field_type( $res, $n );
00182     }
00183 
00184     protected function mysqlDataSeek( $res, $row ) {
00185         return mysql_data_seek( $res, $row );
00186     }
00187 
00188     protected function mysqlError( $conn = null ) {
00189         return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
00190     }
00191 
00192     protected function mysqlRealEscapeString( $s ) {
00193         return mysql_real_escape_string( $s, $this->mConn );
00194     }
00195 
00196     protected function mysqlPing() {
00197         return mysql_ping( $this->mConn );
00198     }
00199 }