Re: PDO Exception Handling Question
| From: | Rodney Topor | Date: | Sun, 02 Apr 2006 21:11:37 +0000 |
| Subject: | Re: PDO Exception Handling Question | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-41652@lists.php.net to get a copy of this message | ||
I did some more checking. If there is an error in the "new PDO(...)"
constructor call, then it does get into the catch block and print an
appropriate error message. (Good. Perhaps I was previously mistaken.)
But if there is an error in the "SELECT" query (either syntax error, or
reference to missing table), then no exception is raised, and control
just continues in the try block with a null result from the query.
Is this the intended behaviour?
On Sun, 2 Apr 2006, chris smith wrote:
On 4/2/06, Rodney Topor <r.topor@griffith.edu.au> wrote:I've just started using PDO with PHP 5.1 and MySQL 5.0. Everything seems to work fine, except for one issue with the following example from the PHP manual. <?php try {Do you mean it doesn't print anything or it doesn't get into the catch block? ie it prints "Error!:<br/>" or it doesn't get into that section at all? -- Postgresql & php tutorials http://www.designmagick.com/$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); foreach ($dbh->query('SELECT * from FOO') as $row) { print_r($row); } $dbh = null;} catch (PDOException $e) {print "Error!: " . $e->getMessage() . "<br/>"; die();} ?> If an error occurs in creating the new PDO instance, or in issuing the PDO query, then a PDOException should be raised. But nothing is ever printed. I've tried running this script, forcing an exception, both from the command line and from the server. But nothing is ever printed. What do I have to do to see the printed string in the catch-block?