MediaWiki  1.28.0
DatabaseMysql.php
Go to the documentation of this file.
1 <?php
35  protected function doQuery( $sql ) {
36  $conn = $this->getBindingHandle();
37 
38  if ( $this->bufferResults() ) {
39  $ret = mysql_query( $sql, $conn );
40  } else {
41  $ret = mysql_unbuffered_query( $sql, $conn );
42  }
43 
44  return $ret;
45  }
46 
52  protected function mysqlConnect( $realServer ) {
53  # Avoid a suppressed fatal error, which is very hard to track down
54  if ( !extension_loaded( 'mysql' ) ) {
55  throw new DBConnectionError(
56  $this,
57  "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n"
58  );
59  }
60 
61  $connFlags = 0;
62  if ( $this->mFlags & self::DBO_SSL ) {
63  $connFlags |= MYSQL_CLIENT_SSL;
64  }
65  if ( $this->mFlags & self::DBO_COMPRESS ) {
66  $connFlags |= MYSQL_CLIENT_COMPRESS;
67  }
68 
69  if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
70  $numAttempts = 2;
71  } else {
72  $numAttempts = 1;
73  }
74 
75  $conn = false;
76 
77  # The kernel's default SYN retransmission period is far too slow for us,
78  # so we use a short timeout plus a manual retry. Retrying means that a small
79  # but finite rate of SYN packet loss won't cause user-visible errors.
80  for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
81  if ( $i > 1 ) {
82  usleep( 1000 );
83  }
84  if ( $this->mFlags & self::DBO_PERSISTENT ) {
85  $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
86  } else {
87  # Create a new connection...
88  $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
89  }
90  }
91 
92  return $conn;
93  }
94 
99  protected function mysqlSetCharset( $charset ) {
100  $conn = $this->getBindingHandle();
101 
102  if ( function_exists( 'mysql_set_charset' ) ) {
103  return mysql_set_charset( $charset, $conn );
104  } else {
105  return $this->query( 'SET NAMES ' . $charset, __METHOD__ );
106  }
107  }
108 
112  protected function closeConnection() {
113  $conn = $this->getBindingHandle();
114 
115  return mysql_close( $conn );
116  }
117 
121  function insertId() {
122  $conn = $this->getBindingHandle();
123 
124  return mysql_insert_id( $conn );
125  }
126 
130  function lastErrno() {
131  if ( $this->mConn ) {
132  return mysql_errno( $this->mConn );
133  } else {
134  return mysql_errno();
135  }
136  }
137 
141  function affectedRows() {
142  $conn = $this->getBindingHandle();
143 
144  return mysql_affected_rows( $conn );
145  }
146 
151  function selectDB( $db ) {
152  $conn = $this->getBindingHandle();
153 
154  $this->mDBname = $db;
155 
156  return mysql_select_db( $db, $conn );
157  }
158 
159  protected function mysqlFreeResult( $res ) {
160  return mysql_free_result( $res );
161  }
162 
163  protected function mysqlFetchObject( $res ) {
164  return mysql_fetch_object( $res );
165  }
166 
167  protected function mysqlFetchArray( $res ) {
168  return mysql_fetch_array( $res );
169  }
170 
171  protected function mysqlNumRows( $res ) {
172  return mysql_num_rows( $res );
173  }
174 
175  protected function mysqlNumFields( $res ) {
176  return mysql_num_fields( $res );
177  }
178 
179  protected function mysqlFetchField( $res, $n ) {
180  return mysql_fetch_field( $res, $n );
181  }
182 
183  protected function mysqlFieldName( $res, $n ) {
184  return mysql_field_name( $res, $n );
185  }
186 
187  protected function mysqlFieldType( $res, $n ) {
188  return mysql_field_type( $res, $n );
189  }
190 
191  protected function mysqlDataSeek( $res, $row ) {
192  return mysql_data_seek( $res, $row );
193  }
194 
195  protected function mysqlError( $conn = null ) {
196  return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
197  }
198 
199  protected function mysqlRealEscapeString( $s ) {
200  $conn = $this->getBindingHandle();
201 
202  return mysql_real_escape_string( $s, $conn );
203  }
204 }
mysqlFetchObject($res)
bufferResults($buffer=null)
Turns buffering of SQL result sets on (true) or off (false).
Definition: Database.php:406
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:1936
mysqlError($conn=null)
mysqlSetCharset($charset)
mysqlFetchField($res, $n)
const DBO_PERSISTENT
Definition: defines.php:11
mysqlConnect($realServer)
$res
Definition: database.txt:21
mysqlFieldName($res, $n)
getBindingHandle()
Get the underlying binding handle, mConn.
Definition: Database.php:3405
mysqlDataSeek($res, $row)
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Database abstraction object for MySQL.
Database abstraction object for PHP extension mysql.
const DBO_SSL
Definition: defines.php:14
const DBO_COMPRESS
Definition: defines.php:15
query($sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition: Database.php:829
mysqlFieldType($res, $n)