Mombu the Php Forum sponsored links

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

sponsored links


Reply
 
1 7th March 18:57
php-bugs
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

Description:
------------
Hello

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

Reproduce code:
---------------
<?php

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


class example_mysqli extends mysqli
{
function __construct($adr, $login, $mdp, $nom_bd)
{
try{
/* 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(),
mysqli_connect_errno());
}

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

function query($query)
{
$result = parent::query($query);
if(mysqli_error($this)){
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";

}

$result->close();
$my->close();

?>


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 http://bugs.php.net/?id=31745&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31745&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31745&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31745&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31745&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31745&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31745&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31745&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31745&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31745&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31745&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31745&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31745&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31745&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31745&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31745&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31745&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31745&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31745&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31745&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31745&r=mysqlcfg
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666