Aside from the database connection, which always throws an exception for an error, you have no error handling for database statements that can fail. You are also using emulated prepared queries. Add the following two lines of code at the same location where you are setting the default fetch mode to assoc -
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // set the error mode to exceptions
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,false); // run real prepared queries