dongzhi6463 2013-06-19 05:37
浏览 90

如何捕获fetchAll(PDO :: FETCH_OBJ)

In my Symfony 1.4 project in one of my class.php file I used the following codes to execute query and fetch object.

$statement = Doctrine_Manager::connection()->execute($query);
$resultset = $statement->fetchAll(PDO::FETCH_OBJ);

I tried to use try-catch block to catch any run-time exceptions. I can easily do that for the first line like

    try {
        $statement = Doctrine_Manager::connection()->execute($query);
    } 
    catch (Exception $exc) {
        echo "custom error message";
    }

But, I this dosen't work for the second line. It always show the following error when I run the page

Fatal error: Call to a member function fetchAll() on a non-object in

\lib\model\doctrine\DeductionInfo.class.php on line 104

How can I resolve this?

  • 写回答

1条回答 默认 最新

  • doukong1901 2013-06-19 06:36
    关注

    Of course it seems to be an invalid query or something like that, resulting in a non-object in your var $statement. Debug or var_dump your $statement var at first.

    Doctrine btw is on top of PDO. By default a PDO construct throws an exception on error. But you have to set error handling for quering to exception (http://php.net/manual/en/pdo.error-handling.php) if you want to use try-catch statements. I don't know exactly the way Doctrine 1 handles this.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程