【问题标题】:Checking if mysqli_query returned any values? [closed]检查 mysqli_query 是否返回任何值? [关闭]
【发布时间】:2013-06-04 12:01:58
【问题描述】:

我有以下代码,我想知道mysqli_query 是否返回任何行,如果返回则返回错误。

$result = mysqli_query($connection, "SELECT * FROM users");
    
if ($result == "") {
    echo "No records found";
} else {
    echo "There is at least one record in the database";
}

如果结果返回为空,我会遇到麻烦。我已经尝试过使用几种东西,但如果什么都没找到,我不知道如何让它正常工作。

【问题讨论】:

    标签: php mysqli


    【解决方案1】:

    像这样使用mysqli_num_rows

    if (mysqli_num_rows($result) == 0) {
        echo "email was not found";
    } else {
        echo "email was found";
    }
    

    【讨论】:

      【解决方案2】:
      if(empty($result))
      {
          echo("email was not found");
      }
      

      【讨论】:

      • 对我不起作用,mysqli_num_rows($result)==0 起作用了。
      【解决方案3】:

      使用mysqli_num_rows 检查是否返回了任何行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-12
        • 2013-06-21
        • 2010-09-17
        • 1970-01-01
        • 2021-02-28
        • 2011-05-22
        相关资源
        最近更新 更多