Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #31745 : Exception doens't catch connection error
User Name
REGISTER NOW! Mark Forums Read

sponsored links

1 7th March 18:57
External User
Posts: 1
Default #31745 : Exception doens't catch connection error

From: tril2632 at hotmail dot com
Operating system: Linux Debian
PHP version: 5.0.3
PHP Bug Type: MySQLi related
Bug description: Exception doens't catch connection error


The problem is that exception are not catching connection problems when
instanciate the mysqli class.

Reproduce code:

/* Create custom exception classes */
class ConnectException extends Exception {}
class QueryException extends Exception {}

class example_mysqli extends mysqli
function __construct($adr, $login, $mdp, $nom_bd)
/* Pass all arguments passed to the constructor on to the parent's
constructor */
$args = func_get_args();
// OK if(!@parent::__construct($adr, $login, $mdp, $nom_bd))
if(!parent::__construct($adr, $login, $mdp, $nom_bd))
throw new ConnectException(mysqli_connect_error(),

/* Throw an error if the connection fails */
throw new ConnectException(mysqli_connect_error(),
catch (Exception $e)
throw new ConnectException(mysqli_connect_error(),

function query($query)
$result = parent::query($query);
throw new QueryException(mysqli_error($this), mysqli_errno($this));

return $result;

try {
$my = new example_mysqli('loclhost','root', '', 'test');
$result = $my->query("SELCT NOW()");

catch(Exception $exception) {
echo "Connection Error\n";

catch(QueryException $exception) {
echo "Query Error\n";

/* Handle exceptions that we weren't expecting */
catch(Exception $exception) {
echo "Who was that masked exception?\n";




Expected result:
it should print me "connection Error"

Actual result:
it always return this error :

mysqli::mysqli() [function.mysqli]: Unknown MySQL server host 'loclhost'
(11001) in c:\wamp\www\wmi\mysqli.php on line 16

Connection Error

With exception php error should NOT be display only the message in the
"catch" should appear !

Edit bug report at
Try a CVS snapshot (php4):
Try a CVS snapshot (php5.0):
Try a CVS snapshot (php5.1):
Fixed in CVS:
Fixed in release:
Need backtrace:
Need Reproduce Script:
Try newer version:
Not developer issue:
Expected behavior:
Not enough info:
Submitted twice:
PHP 3 support discontinued:
Daylight Savings:
IIS Stability:
Install GNU Sed:
Floating point limitations:
No Zend Extensions:
MySQL Configuration Error:
  Reply With Quote

  sponsored links


Thread Tools
Display Modes

Copyright 2006 - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -