Index: branches/5.1.x/core/kernel/db/db_connection.php =================================================================== diff -u -N -r13750 -r14026 --- branches/5.1.x/core/kernel/db/db_connection.php (.../db_connection.php) (revision 13750) +++ branches/5.1.x/core/kernel/db/db_connection.php (.../db_connection.php) (revision 14026) @@ -1,6 +1,6 @@ errorCode == 0); + return $this->errorCode != 0; } /** @@ -233,7 +233,8 @@ function Connect($host, $user, $pass, $db, $force_new = false) { $func = $this->getMetaFunction('connect'); - $this->connectionID = $func($host, $user, $pass, $force_new) or trigger_error("Database connection failed, please check your connection settings", defined('IS_INSTALL') && IS_INSTALL ? E_USER_WARNING : E_USER_ERROR); + $this->connectionID = $func($host, $user, $pass, $force_new); + if ($this->connectionID) { if (defined('DBG_SQL_MODE')) { $this->Query('SET sql_mode = \''.DBG_SQL_MODE.'\''); @@ -244,13 +245,21 @@ } $this->setDB($db); - $this->showError(); } - else { - // simulate error, becase php mysql client doesn't provide such information - $this->errorCode = 2003; - $this->errorMessage = "Can't connect to MySQL server on '$host' (113)"; + + // process error (fatal in most cases) + $func = $this->getMetaFunction('errno'); + $this->errorCode = $this->connectionID ? $func($this->connectionID) : $func(); + + if ( !$this->hasError() ) { + return ; } + + $func = $this->getMetaFunction('error'); + $this->errorMessage = $this->connectionID ? $func($this->connectionID) : $func(); + $error_msg = 'Database connection failed, please check your connection settings.
Error (' . $this->errorCode . '): ' . $this->errorMessage; + + trigger_error($error_msg, defined('IS_INSTALL') && IS_INSTALL ? E_USER_WARNING : E_USER_ERROR); } function ReConnect($host, $user, $pass, $db, $force_new = false) @@ -269,20 +278,30 @@ function showError($sql = '') { $this->setError(0, ''); // reset error - if ($this->connectionID) { - $func = $this->getMetaFunction('errno'); $this->errorCode = $func($this->connectionID); - if ($this->hasError()) { - $func = $this->getMetaFunction('error'); $this->errorMessage = $func($this->connectionID); - if (is_array($this->errorHandler)) { - $func = $this->errorHandler[1]; - $ret = $this->errorHandler[0]->$func($this->errorCode, $this->errorMessage, $sql); - } - else { - $func = $this->errorHandler; - $ret = $func($this->errorCode,$this->errorMessage,$sql); - } - if (!$ret) exit; + + if (!$this->connectionID) { + return ; + } + + $func = $this->getMetaFunction('errno'); + $this->errorCode = $func($this->connectionID); + + if ($this->hasError()) { + $func = $this->getMetaFunction('error'); + $this->errorMessage = $func($this->connectionID); + + if (is_array($this->errorHandler)) { + $func = $this->errorHandler[1]; + $ret = $this->errorHandler[0]->$func($this->errorCode, $this->errorMessage, $sql); } + else { + $func = $this->errorHandler; + $ret = $func($this->errorCode, $this->errorMessage, $sql); + } + + if (!$ret) { + exit; + } } } @@ -297,8 +316,9 @@ */ function handleError($code, $msg, $sql) { - echo 'Processing SQL: '.$sql.'
'; - echo 'Error ('.$code.'): '.$msg.'
'; + echo 'Processing SQL: ' . $sql . '
'; + echo 'Error (' . $code . '): ' . $msg . '
'; + return false; }