Index: trunk/phase3/includes/Database.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | #------------------------------------------------------------------------------ |
28 | 28 | |
29 | 29 | protected $mLastQuery = ''; |
| 30 | + protected $mPHPError = false; |
30 | 31 | |
31 | 32 | protected $mServer, $mUser, $mPassword, $mConn = null, $mDBname; |
32 | 33 | protected $mOut, $mOpened = false; |
— | — | @@ -343,21 +344,23 @@ |
344 | 345 | # so we use a short timeout plus a manual retry. |
345 | 346 | $this->mConn = false; |
346 | 347 | $max = 3; |
| 348 | + $this->installErrorHandler(); |
347 | 349 | for ( $i = 0; $i < $max && !$this->mConn; $i++ ) { |
348 | 350 | if ( $i > 1 ) { |
349 | 351 | usleep( 1000 ); |
350 | 352 | } |
351 | 353 | if ( $this->mFlags & DBO_PERSISTENT ) { |
352 | | - @/**/$this->mConn = mysql_pconnect( $realServer, $user, $password ); |
| 354 | + $this->mConn = mysql_pconnect( $realServer, $user, $password ); |
353 | 355 | } else { |
354 | 356 | # Create a new connection... |
355 | | - @/**/$this->mConn = mysql_connect( $realServer, $user, $password, true ); |
| 357 | + $this->mConn = mysql_connect( $realServer, $user, $password, true ); |
356 | 358 | } |
357 | 359 | if ($this->mConn === false) { |
358 | 360 | #$iplus = $i + 1; |
359 | 361 | #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n"); |
360 | 362 | } |
361 | 363 | } |
| 364 | + $phpError = $this->restoreErrorHandler(); |
362 | 365 | |
363 | 366 | wfProfileOut("dbconnect-$server"); |
364 | 367 | |
— | — | @@ -396,7 +399,7 @@ |
397 | 400 | |
398 | 401 | // Turn off strict mode if it is on |
399 | 402 | } else { |
400 | | - $this->reportConnectionError(); |
| 403 | + $this->reportConnectionError( $phpError ); |
401 | 404 | } |
402 | 405 | |
403 | 406 | $this->mOpened = $success; |
— | — | @@ -405,6 +408,20 @@ |
406 | 409 | } |
407 | 410 | /**@}}*/ |
408 | 411 | |
| 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 | + |
409 | 426 | /** |
410 | 427 | * Closes a database connection. |
411 | 428 | * if it is open : commits any open transactions |