Re: [PHP] Re: MySQL exceptions



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?
.



Relevant Pages

  • Re: [PHP] Re: MySQL exceptions
    ... I don't think MySQL or even mysqli have any kind of exception throwing ... Googling a bit more, I think that MySQL already have some exceptions, the ... echo "Impossible connect to server."; ... error code number would be encapsulated as an ...
    (php.general)
  • Re: [PHP] Re: MySQL exceptions
    ... Em Segunda 09 Abril 2007 21:21, itoctopus escreveu: ... echo "Impossible connect to server."; ... string and error code ), but I believe that with exception I ...
    (php.general)
  • Re: Structured exception information
    ... Doesn't feel as type-safe as advertised. ... What, _exactly_, will the handler do with the separate bits? ... Looking up the localized error message in the dictionary based on the *type-safe* error code that it got from the exception object, ... I'm looking forward to see a convincing solution for error code and the dictionary. ...
    (comp.lang.ada)
  • Re: Exception : an ugly grammer in programming
    ... machinism in programming languages. ... we return error code when we meet an error. ... But how about use exception in OOP? ... Exceptions originally were designed to handle unexpected conditions, ...
    (comp.lang.php)
  • gcc3: C++ exceptions from shared libraries
    ... The shlib defines and throws an exception that is ... sample application (prog) to demonstrate the problem. ... $echo 'WARNING: not restoring timestamps. ... X CShLib obj; ...
    (comp.os.linux.development.apps)