MediaWiki REL1_30
DatabaseMysql.php
Go to the documentation of this file.
1<?php
23namespace Wikimedia\Rdbms;
24
39 protected function doQuery( $sql ) {
40 $conn = $this->getBindingHandle();
41
42 if ( $this->bufferResults() ) {
43 $ret = mysql_query( $sql, $conn );
44 } else {
45 $ret = mysql_unbuffered_query( $sql, $conn );
46 }
47
48 return $ret;
49 }
50
56 protected function mysqlConnect( $realServer ) {
57 # Avoid a suppressed fatal error, which is very hard to track down
58 if ( !extension_loaded( 'mysql' ) ) {
59 throw new DBConnectionError(
60 $this,
61 "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n"
62 );
63 }
64
65 $connFlags = 0;
66 if ( $this->mFlags & self::DBO_SSL ) {
67 $connFlags |= MYSQL_CLIENT_SSL;
68 }
69 if ( $this->mFlags & self::DBO_COMPRESS ) {
70 $connFlags |= MYSQL_CLIENT_COMPRESS;
71 }
72
73 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
74 $numAttempts = 2;
75 } else {
76 $numAttempts = 1;
77 }
78
79 $conn = false;
80
81 # The kernel's default SYN retransmission period is far too slow for us,
82 # so we use a short timeout plus a manual retry. Retrying means that a small
83 # but finite rate of SYN packet loss won't cause user-visible errors.
84 for ( $i = 0; $i < $numAttempts && !$conn; $i++ ) {
85 if ( $i > 1 ) {
86 usleep( 1000 );
87 }
88 if ( $this->mFlags & self::DBO_PERSISTENT ) {
89 $conn = mysql_pconnect( $realServer, $this->mUser, $this->mPassword, $connFlags );
90 } else {
91 # Create a new connection...
92 $conn = mysql_connect( $realServer, $this->mUser, $this->mPassword, true, $connFlags );
93 }
94 }
95
96 return $conn;
97 }
98
103 protected function mysqlSetCharset( $charset ) {
104 $conn = $this->getBindingHandle();
105
106 if ( function_exists( 'mysql_set_charset' ) ) {
107 return mysql_set_charset( $charset, $conn );
108 } else {
109 return $this->query( 'SET NAMES ' . $charset, __METHOD__ );
110 }
111 }
112
116 protected function closeConnection() {
117 $conn = $this->getBindingHandle();
118
119 return mysql_close( $conn );
120 }
121
125 function insertId() {
126 $conn = $this->getBindingHandle();
127
128 return mysql_insert_id( $conn );
129 }
130
134 function lastErrno() {
135 if ( $this->mConn ) {
136 return mysql_errno( $this->mConn );
137 } else {
138 return mysql_errno();
139 }
140 }
141
145 function affectedRows() {
146 $conn = $this->getBindingHandle();
147
148 return mysql_affected_rows( $conn );
149 }
150
155 function selectDB( $db ) {
156 $conn = $this->getBindingHandle();
157
158 $this->mDBname = $db;
159
160 return mysql_select_db( $db, $conn );
161 }
162
163 protected function mysqlFreeResult( $res ) {
164 return mysql_free_result( $res );
165 }
166
167 protected function mysqlFetchObject( $res ) {
168 return mysql_fetch_object( $res );
169 }
170
171 protected function mysqlFetchArray( $res ) {
172 return mysql_fetch_array( $res );
173 }
174
175 protected function mysqlNumRows( $res ) {
176 return mysql_num_rows( $res );
177 }
178
179 protected function mysqlNumFields( $res ) {
180 return mysql_num_fields( $res );
181 }
182
183 protected function mysqlFetchField( $res, $n ) {
184 return mysql_fetch_field( $res, $n );
185 }
186
187 protected function mysqlFieldName( $res, $n ) {
188 return mysql_field_name( $res, $n );
189 }
190
191 protected function mysqlFieldType( $res, $n ) {
192 return mysql_field_type( $res, $n );
193 }
194
195 protected function mysqlDataSeek( $res, $row ) {
196 return mysql_data_seek( $res, $row );
197 }
198
199 protected function mysqlError( $conn = null ) {
200 return ( $conn !== null ) ? mysql_error( $conn ) : mysql_error(); // avoid warning
201 }
202
203 protected function mysqlRealEscapeString( $s ) {
204 $conn = $this->getBindingHandle();
205
206 return mysql_real_escape_string( (string)$s, $conn );
207 }
208}
209
210class_alias( DatabaseMysql::class, 'DatabaseMysql' );
Database abstraction object for MySQL.
Database abstraction object for PHP extension mysql.
mysqlNumRows( $res)
Get number of rows in result.
mysqlFetchObject( $res)
Fetch a result row as an object.
mysqlError( $conn=null)
Returns the text of the error message from previous MySQL operation.
mysqlFieldType( $res, $n)
Get the type of the specified field in a result.
mysqlNumFields( $res)
Get number of fields in result.
mysqlFetchArray( $res)
Fetch a result row as an associative and numeric array.
mysqlFetchField( $res, $n)
Get column information from a result.
mysqlFreeResult( $res)
Free result memory.
mysqlDataSeek( $res, $row)
Move internal result pointer.
mysqlFieldName( $res, $n)
Get the name of the specified field in a result.
bufferResults( $buffer=null)
Turns buffering of SQL result sets on (true) or off (false).
Definition Database.php:438
query( $sql, $fname=__METHOD__, $tempIgnore=false)
Run an SQL query and return the result.
Definition Database.php:888
getBindingHandle()
Get the underlying binding handle, mConn.
$res
Definition database.txt:21
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:1975
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:37