Em Terça 10 Abril 2007 19:26, Richard Lynch escreveu:
>
> I don't think MySQL or even mysqli have any kind of exception throwing
> yet, if ever.
Googling a bit more, I think that MySQL already have some exceptions [1], the
question, now, is: how to catch them with PHP? =]
I think that just using the exceptions name I can do that... So... Let's make
some testes... =]
>
> > 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.
If I don't connect to server, I'll echo an error... Otherwise, I'll select
DB...
>
> You don't put more money into the phone if the line is dead, do you?
>
> :-)
> :
>
> 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.
Sure!
But with try-catch, I get some advantages [2]... It's a _big_ project... So, I
_need_ OOP structure...
>
> 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.
>
> --
BTW, thanks a lot... =]
[1] - http://ehuss.org/mysql/api/mysql.exceptions-module.html
[2] -
http://java.sun.com/docs/books/tutorial/essential/exceptions/advantages.html
--
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--
Agora com fortune:
"You know you're using the computer too much when:
when your life becomes routine enough to write a script to do it for you.
-- smonijhay1"
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php