I have a script that I am updating by replacing the inline mysql queries with PDO prepared statements and queries. When the query is correct or returns a result, it works fine. However, when there is an error in the query statement try/catch dies not work. For example, I used this test code:
$query = $this->dbh->prepare('SELEC menu_item, hyperlink, admin FROM top_menu;');
try
{
$query->execute();
$row = $query->fetch(PDO::FETCH_ASSOC));
die("success");
}
catch(Exception $e)
{
die("fail");
}
The query is wrong ("SELEC" instead of "SELECT"), so the flow of the script should go into the exception/error brackets, and yet it doesn't; I keep getting "success". I've tried catch(PDOException $e) instead of catch(Exception $e) with the exact same results.
What am I doing wrong, and how can I fix this? Thanks.