【问题标题】:Fatal error: Uncaught TypeError: mysqli_fetch_assoc() [duplicate]致命错误:未捕获的类型错误:mysqli_fetch_assoc() [重复]
【发布时间】:2021-07-08 04:31:50
【问题描述】:

我的代码:

    $zaman = '%'.date('Y-m-d').'%';
    $Sorgu = mysqli_query($link, "SELECT COUNT( * ) AS sayi, ip 
      FROM visitors 
      WHERE zaman LIKE '$zaman' 
      AND sayfa LIKE '%admin%'
      GROUP BY ip ORDER BY sayi ASC");
    
    while($X = mysqli_fetch_assoc($Sorgu)){
        if($X[sayi] > 2) echo $X[ip].' ip address '.$X[sayi].' <br>';
    }

但我收到以下错误。

致命错误:未捕获的类型错误:mysqli_fetch_assoc():参数 #1 ($result) 必须是 mysqli_result 类型,/home/xxxxxxx/public_html/ip.php:28 中给出的 bool 堆栈跟踪:#0 /home/xxxxxxx /public_html/ip.php(28): mysqli_fetch_assoc(false) #1 {main} 在第 28 行的 /home/xxxxxxx/public_html/ip.php 中抛出

我该如何解决这个问题?

【问题讨论】:

标签: php mysqli php-8


【解决方案1】:

错误本身说参数 #1 ($result) 必须是 mysqli_result 类型,bool 给定, 那是你的代码 while($X = mysqli_fetch_assoc($Sorgu)){ 使用 $Sorgu 是 bool 类型的,应该是 mysqli_result,这意味着你的最后一个查询导致 bool,你应该更正查询或者在 while 循环之前你应该检查结果的类型不是 bool,希望这会帮助

【讨论】:

    猜你喜欢
    • 2020-07-28
    • 2022-08-14
    • 2022-12-10
    • 2018-09-06
    • 2016-10-28
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多