I have been using the standard PHP error reporting, but decided to attempt a try catch with PDO. I'm going to turn off error reporting with error_reporting(0)
and use custom error handling.
My try-catch
or !isnull(error)
doesn't fire. Can some suggest how to achieve the error handling without the default reporting?
What am i doing wrong?
PHP
$db = connect();
try
{
foreach ($data['ids'] as $item_id)
{
$sql =
"UPDATE item
SET verified = !verified
WHERE item_id = :room_id"; //this line is incorrect and should cause error
$update = $db -> prepare($sql);
$update -> bindParam(":item_id", $item_id);
$update -> execute();
$error = $db -> errorInfo();
$update -> closeCursor();
}
}
catch(PDOException $e)
{
echo "ERROR : Server Error -". $e -> getMessage();
}
if (!is_null($error[2]))
{
echo "Query failed! ". $error[2];
}