Re: mdb2 error handling
| From: | Lukas Kahwe Smith | Date: | Sun, 17 Sep 2006 18:05:44 +0000 |
| Subject: | Re: mdb2 error handling | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25156@lists.php.net to get a copy of this message | ||
petr bartos wrote:
Hi, is there any forum, please, where can MDB2 users discuss their troubles and wins? I am trying to learn MDB2 but currently missing (cannot found a solution on web) how to get over * too much abstract error messages. actual result: MDB2 Error: syntax error expected result: | #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FdROM authors' at line 1 |ideally followed by full query string. Or leave the db error to my error handler. (Have tried 'debug' and 'debug_handler' option but without any luck so far). If you could point me with just few words to the right direction, I would be very obliged to you.The error message is trying to tell you that you have a syntax error near 'FdROM authors' .. in this case i would think you wanted to pass in 'FROM authors' without the 'd' MDB2 only knows its a syntax error, the error test is generated by mysql.
* need to check on errors after every single db query. If such error occurs (bad sql query or even bad sql exec command), the willing behavior is the one that will stop whole script (something like "die()" but in custom error handler), because it has indicated poorly checked input data or other programmer's fault. I can imagine only a few practical situations, in which is this proposed behavior unwilling - on the other hand, thousands of cases when it's neccessary. Even in the tutorial is almost after every command |if (PEAR::isError( $id)) {yes you can do this with PEAR_Error. you would just set a global error handler and "expect" error codes as needed. // MDB2 allows setting a global error handler PEAR::setErrorHandling(PEAR_ERROR_DIE); // expect no such table error $mdb2->expectError(MDB2_ERROR_NOSUCHTABLE); $res = $mdb2->queryAll($sql); $mdb2->popExpect(); // table didnt exist? if (MDB2::isError($res,MDB2_ERROR_NOSUCHTABLE)) {..} More information about PEAR_Error can be found here: http://www.php-mag.net/magphpde/magphpde_article/psecom,id,330,nodeid,21.html regards, Lukasdie($id->getMessage());}| ... so... why not make a rule from this "politics" with a possibility to make exceptions? It would spend many lines of code, make the code more readable and even more secure.