donglanche9257 2015-01-19 20:43
浏览 40
已采纳

移动到xampp 1.8.3后pdo致命错误

after move all rowCount() Functions return fatal error

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

i use this function like this :

$co = $pdo->query("SELECT * FROM `tbl_users`");
$pages->items_total = $co->rowCount();
  • 写回答

1条回答 默认 最新

  • duangu4980 2015-01-19 20:46
    关注

    This means something went wrong while executing the query. Perhaps something went wrong with the update and MySQL isn't running anymore? Verify this, make sure MySQL is running.

    Also, you can try to run the same query in PhpMyAdmin to see if that works. If it does, you're sure this is a problem with PDO. If it doesn't, something must be wrong with the MySQL server.

    But perhaps the easiest way to debug is to do something like this:

    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    With this, PDO will throw an exception when the query fails. Then put the query in a try ... catch block:

    try {
        $co = $pdo->query("SELECT * FROM `tbl_users`");
        $pages->items_total = $co->rowCount();
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    

    This will give you more debug info. When the query fails, the exception will be caught by the catch block, and the message will be outputted. This message usually tells you where the problem is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数
  • ¥15 关于#线性回归#的问题:【统计】回归系数要转化为相关系数才能进行Fisher' Z转化吗(相关搜索:回归模型)
  • ¥100 使用matlab解决含分段变量的优化问题