MediaWiki  1.23.2
DatabaseMysql.php
Go to the documentation of this file.
1 <?php
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 
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 
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 
106  protected function closeConnection() {
107  return mysql_close( $this->mConn );
108  }
109 
113  function insertId() {
114  return mysql_insert_id( $this->mConn );
115  }
116 
120  function lastErrno() {
121  if ( $this->mConn ) {
122  return mysql_errno( $this->mConn );
123  } else {
124  return mysql_errno();
125  }
126  }
127 
131  function affectedRows() {
132  return mysql_affected_rows( $this->mConn );
133  }
134 
139  function selectDB( $db ) {
140  $this->mDBname = $db;
141 
142  return mysql_select_db( $db, $this->mConn );
143  }
144 
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 }
DatabaseMysqlBase
Database abstraction object for MySQL.
Definition: DatabaseMysqlBase.php:32
DatabaseMysql\mysqlDataSeek
mysqlDataSeek( $res, $row)
Move internal result pointer.
Definition: DatabaseMysql.php:184
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
DatabaseMysql\mysqlRealEscapeString
mysqlRealEscapeString( $s)
Definition: DatabaseMysql.php:192
DatabaseMysql\closeConnection
closeConnection()
Definition: DatabaseMysql.php:106
DatabaseMysql\mysqlFetchObject
mysqlFetchObject( $res)
Fetch a result row as an object.
Definition: DatabaseMysql.php:156
DBO_PERSISTENT
const DBO_PERSISTENT
Definition: Defines.php:44
DatabaseBase\query
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:1001
$n
$n
Definition: RandomTest.php:76
DatabaseMysql\affectedRows
affectedRows()
Definition: DatabaseMysql.php:131
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
DatabaseMysql\mysqlFieldName
mysqlFieldName( $res, $n)
Get the name of the specified field in a result.
Definition: DatabaseMysql.php:176
$s
$s
Definition: mergeMessageFileList.php:156
DatabaseMysql\mysqlNumRows
mysqlNumRows( $res)
Get number of rows in result.
Definition: DatabaseMysql.php:164
DBO_COMPRESS
const DBO_COMPRESS
Definition: Defines.php:48
DatabaseMysql\doQuery
doQuery( $sql)
Definition: DatabaseMysql.php:35
DatabaseMysql\mysqlFetchArray
mysqlFetchArray( $res)
Fetch a result row as an associative and numeric array.
Definition: DatabaseMysql.php:160
DBO_SSL
const DBO_SSL
Definition: Defines.php:47
DBConnectionError
Definition: DatabaseError.php:98
DatabaseMysql\selectDB
selectDB( $db)
Definition: DatabaseMysql.php:139
DatabaseMysql\mysqlConnect
mysqlConnect( $realServer)
Definition: DatabaseMysql.php:50
DatabaseBase\bufferResults
bufferResults( $buffer=null)
Turns buffering of SQL result sets on (true) or off (false).
Definition: Database.php:368
DatabaseMysql\mysqlNumFields
mysqlNumFields( $res)
Get number of fields in result.
Definition: DatabaseMysql.php:168
DatabaseMysql\mysqlFetchField
mysqlFetchField( $res, $n)
Get column information from a result.
Definition: DatabaseMysql.php:172
DatabaseMysql\mysqlFreeResult
mysqlFreeResult( $res)
Free result memory.
Definition: DatabaseMysql.php:152
DatabaseMysql\mysqlError
mysqlError( $conn=null)
Returns the text of the error message from previous MySQL operation.
Definition: DatabaseMysql.php:188
DatabaseMysql\mysqlSetCharset
mysqlSetCharset( $charset)
Definition: DatabaseMysql.php:95
DatabaseMysql
Database abstraction object for PHP extension mysql.
Definition: DatabaseMysql.php:30
DatabaseMysql\lastErrno
lastErrno()
Definition: DatabaseMysql.php:120
$res
$res
Definition: database.txt:21
DatabaseMysql\insertId
insertId()
Definition: DatabaseMysql.php:113
DatabaseMysql\mysqlFieldType
mysqlFieldType( $res, $n)
Get the type of the specified field in a result.
Definition: DatabaseMysql.php:180
DatabaseMysql\mysqlPing
mysqlPing()
Ping a server connection or reconnect if there is no connection.
Definition: DatabaseMysql.php:196
DatabaseMysql\getServerVersion
getServerVersion()
Definition: DatabaseMysql.php:148