PDO Exception Handling Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 {
   $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?

Rodney Topor

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux