No error when there should be error

My code:

$sql = “SELECT * FROM bus170 limit 100”;
try {
$db->query($sql);
} catch (PDOException $e) {
echo $e->getMessage();
}

Why is there no error when I purposely use a nonexistent table name, using this code?

Have you enabled PDO exceptions? As I recall they are not enabled by default.

$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
3 Likes

That’s it! Thank-you!

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.