#31745 [Opn->Bgs]: Exception doens't catch connection error
| From: | tony2001@php.net | Date: | Fri, 28 Jan 2005 20:24:02 +0000 |
| Subject: | #31745 [Opn->Bgs]: Exception doens't catch connection error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-73003@lists.php.net to get a copy of this message | ||
ID: 31745
Updated by: tony2001@php.net
Reported By: tril2632 at hotmail dot com
-Status: Open
+Status: Bogus
Bug Type: MySQLi related
Operating System: Linux Debian
PHP Version: 5.0.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Using exceptions doesn't mean that all warnings/notices/etc. are
supressed.
Previous Comments:
------------------------------------------------------------------------
[2005-01-28 16:27:52] tril2632 at hotmail dot com
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 this bug report at http://bugs.php.net/?id=31745&edit=1