Re: Re: MySQL exceptions
| From: | Davi | Date: | Mon, 09 Apr 2007 23:34:31 +0000 |
| Subject: | Re: Re: MySQL exceptions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252388@lists.php.net to get a copy of this message | ||
Em Segunda 09 Abril 2007 21:21, itoctopus escreveu:
> Use the @ in front of the statement and then check the result if it's
> valid.
>
> --
> itoctopus - http://www.itoctopus.com
I already use it, but I believe that try-catch would be _more_ useful...
With try-cath I can _get_ more errors instead with a if-then-else clasule...
i.e.: with if-then-else:
$connect=mysql_connect(...);
if($connect)
{
if(!(mysql_select_db(...,$connect)))
{
echo "Impossible select db.";
}
}
else
{
echo "Impossible connect to server.";
}
If I want to get some debug info, I put some mysql_error() and I get the error
string and error code (mysql_errno()), but I believe that with exception I
can get some useful error message without... hum... *critical* infos...
try
{
$connect=mysql_connect(...);
mysql_select_db(...,$connect);
}
catch (CONNECTION_EXCEPTION $e)
{
echo "Impossible connect: ".$e->get_message();
}
catch (SELECT_EXCEPTION $e)
{
echo "Impossible select db: ".$e->get_message();
}
catch (ANOTHER_USEFUL_EXCEPTION $e)
{
echo "another error: ".$e->get_message();
}
catch (Exception $e)
{
echo "Unknown error: ".$e->get_message();
}
I'm right?
TIA
--
Davi Vidal
davividal@siscompar.com.br
davividal@gmail.com
--
Agora com fortune:
"Stanford women are responsible for the success of many Stanford men:
they give them "just one more reason" to stay in and study every night."