douminfu8033 2016-01-28 16:42
浏览 36

PDO错误处理没有被触发

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];
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大