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? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: MySQL exceptions
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
[PHP] Re: MySQL exceptions
Use the @ in front of the statement and then check the result if it's valid. -- itoctopus - http://www.itoctopus.com Davi [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all! I'm developing an OOP app using PHP 5. I want to use try-catch with mysql functions. So, the question is: what are the exceptions classes of MySQL? Where can I found it? TIA -- Davi Vidal [EMAIL PROTECTED] [EMAIL PROTECTED] -- Agora com fortune: BOFH Excuse #426: internet is needed to catch the etherbunny -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: MySQL exceptions
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 [EMAIL PROTECTED] [EMAIL PROTECTED] -- 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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php