doudianhuo1129 2012-07-21 19:37
浏览 96
已采纳

Mysqli数据库连接问题

I am currently using mysqli to crate a connection to my database. My host server doesnt support PDO connections so that is why I am using mysqli. When making the connection I am getting this error:

Fatal error: Call to undefined method mysqli_result::fetchAll()

Is fetchAll() not part of mysqli?

PHP Connect to DB

$mysqli = new mysqli('localhost', 'user', 'password', 'database');

if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}
else {
echo ('Success... '); 
}

    $sql = "SELECT * 
            FROM `categories`
            WHERE `master` = 0";
    $statement = $mysqli->query($sql);
    $list = $statement->fetchAll();
  • 写回答

4条回答 默认 最新

  • duanpaxin3531 2012-07-21 20:08
    关注

    When you call $mysqli->query($sql), this can return a mysqli_result object, or the value false in case of an error. I think that your query is not successful, and returns the value false, and of course if you ask for false->fetchAll() this will give an error message.

    So you have to check first, if the query was successful (use the === operator and check for false), and afterwards you can work with the result of the query.

    P.S. That's why i never write functions myself, with mixed typed return values...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据