dpzff20644 2014-05-14 16:16
浏览 148
已采纳

PHP mysqli_fetch_all给了我一个空白的屏幕

I just pushed something from my local machine to the live site and I get blank pages everywhere. I tracked down the problem to mysqli_fetch_all when I use that everything breaks. Why is it doing this? and how do I fix it? if I use mysqli_fetch_array or mysqli_fetch_row or mysqli_fetch_assoc it works but my data is not displayed properly.

This is one the functions that is breaking:

function getUserFields($connection){

        $query = mysqli_query($connection, "DESCRIBE `adminUsers`");
        $results = mysqli_fetch_all($query, MYSQLI_ASSOC);
        return $results;

}

The $connection is the connection to my database, I have confirmed that works and $query sting is getting populated, it just the mysqli_fetch_all does not work, how could I fix this in the function without adjusting how the data is displayed currently.

  • 写回答

2条回答 默认 最新

  • douweng7308 2014-05-14 16:33
    关注

    The function mysqli_fetch_all() and its object oriented counterpart (mysqli_result::fetch_all) are only available in PHP 5.3 and later.

    It appears your server is running a lower version of PHP, or you're missing MySQL Native Driver (which this function depends on), which explains why the other fetch functions work and this doesn't.

    From the Manual:

    mysqli_fetch_all
    mysqli_result::fetch_all
    (PHP 5 >= 5.3.0)

    For future debugging, turn errors on or refer to your error log because this will usually help to identify the problem.

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    If you don't have access to upgrade the PHP version, or install MySQLND, you can simply convert the code to manually iterate using mysqli_fetch_assoc():

    function getUserFields($connection){
        $query = mysqli_query($connection, "DESCRIBE `adminUsers`");    
        $results = array();
    
        if($query){
            while($row = mysqli_fetch_assoc($query)){
                $results[] = $row;
            }
        }
    
        return $results;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀