r35838 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35837‎ | r35838 | r35839 >
Date:01:44, 4 June 2008
Author:tstarling
Status:old
Tags:
Comment:
Capture PHP errors from mysql_connect(). Apparently this is the only place connection errors are available in PHP 5.2.6.
Modified paths:
  • /trunk/phase3/includes/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Database.php
@@ -26,6 +26,7 @@
2727 #------------------------------------------------------------------------------
2828
2929 protected $mLastQuery = '';
 30+ protected $mPHPError = false;
3031
3132 protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname;
3233 protected $mOut, $mOpened = false;
@@ -343,21 +344,23 @@
344345 # so we use a short timeout plus a manual retry.
345346 $this->mConn = false;
346347 $max = 3;
 348+ $this->installErrorHandler();
347349 for ( $i = 0; $i < $max && !$this->mConn; $i++ ) {
348350 if ( $i > 1 ) {
349351 usleep( 1000 );
350352 }
351353 if ( $this->mFlags & DBO_PERSISTENT ) {
352 - @/**/$this->mConn = mysql_pconnect( $realServer, $user, $password );
 354+ $this->mConn = mysql_pconnect( $realServer, $user, $password );
353355 } else {
354356 # Create a new connection...
355 - @/**/$this->mConn = mysql_connect( $realServer, $user, $password, true );
 357+ $this->mConn = mysql_connect( $realServer, $user, $password, true );
356358 }
357359 if ($this->mConn === false) {
358360 #$iplus = $i + 1;
359361 #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n");
360362 }
361363 }
 364+ $phpError = $this->restoreErrorHandler();
362365
363366 wfProfileOut("dbconnect-$server");
364367
@@ -396,7 +399,7 @@
397400
398401 // Turn off strict mode if it is on
399402 } else {
400 - $this->reportConnectionError();
 403+ $this->reportConnectionError( $phpError );
401404 }
402405
403406 $this->mOpened = $success;
@@ -405,6 +408,20 @@
406409 }
407410 /**@}}*/
408411
 412+ protected function installErrorHandler() {
 413+ $this->mPHPError = false;
 414+ set_error_handler( array( $this, 'connectionErrorHandler' ) );
 415+ }
 416+
 417+ protected function restoreErrorHandler() {
 418+ restore_error_handler();
 419+ return $this->mPHPError;
 420+ }
 421+
 422+ protected function connectionErrorHandler( $errno, $errstr ) {
 423+ $this->mPHPError = $errstr;
 424+ }
 425+
409426 /**
410427 * Closes a database connection.
411428 * if it is open : commits any open transactions

Status & tagging log