Re: [PHP] Re: MySQL exceptions
- From: ceo@xxxxxxxxx ("Richard Lynch")
- Date: Tue, 10 Apr 2007 17:26:42 -0500 (CDT)
On Mon, April 9, 2007 6:34 pm, Davi wrote:
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 don't think MySQL or even mysqli have any kind of exception throwing
yet, if ever.
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 you didn't connect to the server, doing the select_db is rather
pointless, so I'd check the $connect FIRST, and deal with that
completely before trying to use a dead connection.
You don't put more money into the phone if the line is dead, do you?
:-)
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...
There is nothing you'd be able to get from a thrown exception that you
can't get with mysql_errno() and vice versa, in theory.
In reality, it will probably be some time before every possile MySQL
error code number (and they are legion) would be encapsulated as an
Exception.
So for maxiumu customization, short-term, mysql_errno() is probably
the way to go.
I often, for example, simply want to IGNORE mysql_errno($connection)
== 1062 becaue it's just a duplicate key insert, and that means I've
already dealt with whatever I was trying to insert, and just don't
care.
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
.
- Follow-Ups:
- Re: [PHP] Re: MySQL exceptions
- From: Davi
- Re: [PHP] Re: MySQL exceptions
- References:
- MySQL exceptions
- From: Davi
- Re: MySQL exceptions
- From: "itoctopus"
- Re: [PHP] Re: MySQL exceptions
- From: Davi
- MySQL exceptions
- Prev by Date: Re: [PHP] Oputting Forms Within a Class
- Next by Date: Re: [PHP] Novice PHP Question - Listing Folder Contents
- Previous by thread: Re: [PHP] Re: MySQL exceptions
- Next by thread: Re: [PHP] Re: MySQL exceptions
- Index(es):
Relevant Pages
|