r66638 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66637‎ | r66638 | r66639 >
Date:02:12, 19 May 2010
Author:mah
Status:ok (Comments)
Tags:
Comment:
* Remove compatibility code for pre-5.1 versions of PHP
* Re-connect to db after error in strencode()
Modified paths:
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -74,7 +74,7 @@
7575 }
7676 if ($this->mConn === false) {
7777 #$iplus = $i + 1;
78 - #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n");
 78+ #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n");
7979 }
8080 }
8181 $phpError = $this->restoreErrorHandler();
@@ -90,7 +90,7 @@
9191 substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" );
9292 $success = false;
9393 }
94 -
 94+
9595 wfProfileOut("dbconnect-$server");
9696
9797 if ( $dbName != '' && $this->mConn !== false ) {
@@ -233,7 +233,7 @@
234234 }
235235
236236 function affectedRows() { return mysql_affected_rows( $this->mConn ); }
237 -
 237+
238238 /**
239239 * Estimate rows in dataset
240240 * Returns estimated count, based on EXPLAIN output
@@ -255,7 +255,7 @@
256256 }
257257
258258 $this->freeResult($res);
259 - return $rows;
 259+ return $rows;
260260 }
261261
262262 function fieldInfo( $table, $field ) {
@@ -277,28 +277,26 @@
278278 }
279279
280280 function strencode( $s ) {
281 - return mysql_real_escape_string( $s, $this->mConn );
 281+ $sQuoted = mysql_real_escape_string( $s, $this->mConn );
 282+
 283+ if($sQuoted === false) {
 284+ $this->ping();
 285+ $sQuoted = mysql_real_escape_string( $s, $this->mConn );
 286+ }
 287+ return $sQuoted;
282288 }
283289
284290 function ping() {
285 - if( !function_exists( 'mysql_ping' ) ) {
286 - wfDebug( "Tried to call mysql_ping but this is ancient PHP version. Faking it!\n" );
287 - return true;
288 - }
289291 $ping = mysql_ping( $this->mConn );
290292 if ( $ping ) {
291293 return true;
292294 }
293295
294 - // Need to reconnect manually in MySQL client 5.0.13+
295 - if ( version_compare( mysql_get_client_info(), '5.0.13', '>=' ) ) {
296 - mysql_close( $this->mConn );
297 - $this->mOpened = false;
298 - $this->mConn = false;
299 - $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname );
300 - return true;
301 - }
302 - return false;
 296+ mysql_close( $this->mConn );
 297+ $this->mOpened = false;
 298+ $this->mConn = false;
 299+ $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname );
 300+ return true;
303301 }
304302
305303 function getServerVersion() {
@@ -351,8 +349,8 @@
352350 $items = array();
353351
354352 foreach( $write as $table ) {
355 - $tbl = $this->tableName( $table ) .
356 - ( $lowPriority ? ' LOW_PRIORITY' : '' ) .
 353+ $tbl = $this->tableName( $table ) .
 354+ ( $lowPriority ? ' LOW_PRIORITY' : '' ) .
357355 ' WRITE';
358356 $items[] = $tbl;
359357 }
@@ -382,7 +380,7 @@
383381 $this->query( "SET sql_big_selects=$encValue", __METHOD__ );
384382 }
385383
386 -
 384+
387385 /**
388386 * Determines if the last failure was due to a deadlock
389387 */
@@ -391,7 +389,7 @@
392390 }
393391
394392 /**
395 - * Determines if the last query error was something that should be dealt
 393+ * Determines if the last query error was something that should be dealt
396394 * with by pinging the connection and reissuing the query
397395 */
398396 function wasErrorReissuable() {
@@ -402,7 +400,7 @@
403401 * Determines if the last failure was due to the database being read-only.
404402 */
405403 function wasReadOnlyError() {
406 - return $this->lastErrno() == 1223 ||
 404+ return $this->lastErrno() == 1223 ||
407405 ( $this->lastErrno() == 1290 && strpos( $this->lastError(), '--read-only' ) !== false );
408406 }
409407
@@ -420,7 +418,7 @@
421419 $res = $this->query( "SHOW CREATE TABLE $oldName" );
422420 $row = $this->fetchRow( $res );
423421 $oldQuery = $row[1];
424 - $query = preg_replace( '/CREATE TABLE `(.*?)`/',
 422+ $query = preg_replace( '/CREATE TABLE `(.*?)`/',
425423 "CREATE $tmp TABLE `$newName`", $oldQuery );
426424 if ($oldQuery === $query) {
427425 # Couldn't do replacement

Comments

#Comment by MaxSem (talk | contribs)   04:18, 19 May 2010

$sQuoted? We generally don't use Hungarian notation.

#Comment by MarkAHershberger (talk | contribs)   05:36, 19 May 2010

$sQuoted is $s quoted :)

#Comment by QChris (WMF) (talk | contribs)   20:48, 3 March 2012

The log message says to remove "pre-5.1 versions of PHP", but kills a guard for 5.0.13 of /MySQL/.

Current INSTALL file lists >= MySQL-4.0.14 as requirement. So for users of MySQL between 4.0.14 and 5.0.(1)3, this yields an additional connection attempt. But I assume the code is not executed often enough and the user base for those versions is too small to be relevant ;)

(If there are relevant users for those versions, the MySQL ChangeLog reports the change in default reconnection settings in version 5.0.3, not 5.0.13; just in case some problems arise between those versions)

Status & tagging log