致命错误:调用未定义的方法mysqli :: num_rows() [英] Fatal error: Call to undefined method mysqli::num_rows()
问题描述
我正在寻求有关PHP的帮助.我检查了一下代码,发现其中没有任何错误.
Hi I am requesting help with my PHP. I checked the code through and I couldn't spot any errors in it.
我对PHP不太满意,希望你们中的任何人都能帮忙.
I'm not that great with PHP, and I hope any of you could help.
它应该返回false或true,但我收到此错误
It should return either false or true but, I get this error
Fatal error: Call to undefined method mysqli::num_rows()
这是我的代码:
$mysqli
是我的mysqli数据库连接器.
$mysqli
is my mysqli database connector.
$email = $_SESSION["email"];
function isbanned($email){
global $mysqli;
if($mysqli->num_rows("SELECT * FROM `user_bans` WHERE `banned_id` = '".$email."' LIMIT 1") > 0){
return true;
}
return false;
}
isbanned($email);
这就是我所有被禁止脚本的代码.
That's all my code for the banned script.
提前谢谢.
推荐答案
那不是使用该函数的方式.首先,您执行查询,然后然后检查以查看从返回的结果对象返回了多少行:
That's not how that function is used. First you execute your query and then you check to see how many rows were returned from the returned result object:
$result = $mysqli->query("SELECT * FROM `user_bans` WHERE `banned_id` = '".$email."' LIMIT 1");
if($result->num_rows > 0){
return true;
}
这篇关于致命错误:调用未定义的方法mysqli :: num_rows()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!