Re: Re: MySQL exceptions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux