检查 mysqli_query 是否返回任何值? [英] Checking if mysqli_query returned any values?

查看:33
本文介绍了检查 mysqli_query 是否返回任何值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have the following code and I would like to know if mysqli_query returned any rows and if so return an error.

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

如果结果返回为空,我就会遇到麻烦.我已经尝试使用了几种东西,但如果没有找到任何东西,我无法弄清楚如何让它正常工作.

I'm having trouble if the results come back as empty. I've tried using several things and can't figure out how to get it work correctly if nothing is found.

推荐答案

使用 mysqli_num_rows 检查是否有任何行返回.

Use mysqli_num_rows to check if any rows were returned or not.

这篇关于检查 mysqli_query 是否返回任何值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆