I am learning to work with PHP and have a simple problem.
Try print_r($db->errorInfo());
print_r($db->errorInfo());
Probably the prepare failed so you can't use it.