移动到xampp 1.8.3后pdo致命错误

移动到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();

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.