[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/db/ -> DatabaseMysql.php (source)

   1  <?php
   2  /**
   3   * This is the MySQL database abstraction layer.
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup Database
  22   */
  23  
  24  /**
  25   * Database abstraction object for PHP extension mysql.
  26   *
  27   * @ingroup Database
  28   * @see Database
  29   */
  30  class DatabaseMysql extends DatabaseMysqlBase {
  31      /**
  32       * @param string $sql
  33       * @return resource False on error
  34       */
  35  	protected function doQuery( $sql ) {
  36          if ( $this->bufferResults() ) {
  37              $ret = mysql_query( $sql, $this->mConn );
  38          } else {
  39              $ret = mysql_unbuffered_query( $sql, $this->mConn );
  40          }
  41  
  42          return $ret;
  43      }
  44  
  45      /**
  46       * @param string $realServer
  47       * @return bool|resource MySQL Database connection or false on failure to connect
  48       * @throws DBConnectionError
  49       */
  50  	protected function mysqlConnect( $realServer ) {
  51          # Fail now
  52          # Otherwise we get a suppressed fatal error, which is very hard to track down
  53          if ( !extension_loaded( 'mysql' ) ) {
  54              throw new DBConnectionError(
  55                  $this,
  56                  "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n"
  57              );
  58          }
  59  
  60          $connFlags = 0;
  61          if ( $this->mFlags & DBO_SSL ) {
  62              $connFlags |= MYSQL_CLIENT_SSL;
  63          }
  64          if ( $this->mFlags & DBO_COMPRESS ) {
  65              $connFlags |= MYSQL_CLIENT_COMPRESS;
  66          }
  67  
  68          if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
  69              $numAttempts = 2;
  70          } else {
  71              $numAttempts = 1;
  72          }
  73  
  74          $conn = false;
  75  
  76          for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
  77              if ( $i > 1 ) {
  78                  usleep( 1000 );
  79              }
  80              if ( $this->mFlags & DBO_PERSISTENT ) {
  81                  $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
  82              } else {
  83                  # Create a new connection...
  84                  $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
  85              }
  86          }
  87  
  88          return $conn;
  89      }
  90  
  91      /**
  92       * @param string $charset
  93       * @return bool
  94       */
  95  	protected function mysqlSetCharset( $charset ) {
  96          if ( function_exists( 'mysql_set_charset' ) ) {
  97              return mysql_set_charset( $charset, $this->mConn );
  98          } else {
  99              return $this->query( 'SET NAMES ' . $charset, __METHOD__ );
 100          }
 101      }
 102  
 103      /**
 104       * @return bool
 105       */
 106  	protected function closeConnection() {
 107          return mysql_close( $this->mConn );
 108      }
 109  
 110      /**
 111       * @return int
 112       */
 113  	function insertId() {
 114          return mysql_insert_id( $this->mConn );
 115      }
 116  
 117      /**
 118       * @return int
 119       */
 120  	function lastErrno() {
 121          if ( $this->mConn ) {
 122              return mysql_errno( $this->mConn );
 123          } else {
 124              return mysql_errno();
 125          }
 126      }
 127  
 128      /**
 129       * @return int
 130       */
 131  	function affectedRows() {
 132          return mysql_affected_rows( $this->mConn );
 133      }
 134  
 135      /**
 136       * @param string $db
 137       * @return bool
 138       */
 139  	function selectDB( $db ) {
 140          $this->mDBname = $db;
 141  
 142          return mysql_select_db( $db, $this->mConn );
 143      }
 144  
 145      /**
 146       * @return string
 147       */
 148  	function getServerVersion() {
 149          return mysql_get_server_info( $this->mConn );
 150      }
 151  
 152  	protected function mysqlFreeResult( $res ) {
 153          return mysql_free_result( $res );
 154      }
 155  
 156  	protected function mysqlFetchObject( $res ) {
 157          return mysql_fetch_object( $res );
 158      }
 159  
 160  	protected function mysqlFetchArray( $res ) {
 161          return mysql_fetch_array( $res );
 162      }
 163  
 164  	protected function mysqlNumRows( $res ) {
 165          return mysql_num_rows( $res );
 166      }
 167  
 168  	protected function mysqlNumFields( $res ) {
 169          return mysql_num_fields( $res );
 170      }
 171  
 172  	protected function mysqlFetchField( $res, $n ) {
 173          return mysql_fetch_field( $res, $n );
 174      }
 175  
 176  	protected function mysqlFieldName( $res, $n ) {
 177          return mysql_field_name( $res, $n );
 178      }
 179  
 180  	protected function mysqlFieldType( $res, $n ) {
 181          return mysql_field_type( $res, $n );
 182      }
 183  
 184  	protected function mysqlDataSeek( $res, $row ) {
 185          return mysql_data_seek( $res, $row );
 186      }
 187  
 188  	protected function mysqlError( $conn = null ) {
 189          return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
 190      }
 191  
 192  	protected function mysqlRealEscapeString( $s ) {
 193          return mysql_real_escape_string( $s, $this->mConn );
 194      }
 195  
 196  	protected function mysqlPing() {
 197          return mysql_ping( $this->mConn );
 198      }
 199  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1