mysql_num_rows给出错误"mysql_num_rows()期望参数1为资源". [英] mysql_num_rows giving error "mysql_num_rows() expects parameter 1 to be resource"
本文介绍了mysql_num_rows给出错误"mysql_num_rows()期望参数1为资源".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public function doesUserExist($u) {
$this->dbConnect();
mysql_select_db($this->database);
$sUser = mysql_real_escape_string($u);
$query = "SELECT username FROM $this->table WHERE username='$sUser'";
$doesFieldExist = false;
if (mysql_num_rows($query) > 0) {
$doesFieldExist = true;
}
$this->dbDisconnect();
return $doesFieldExist;
}
我在这条线上出现错误(60)
I get an error on this line (60)
if (mysql_num_rows($query) > 0) {
错误是:
Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\Users\Tom\Dropbox\public_html\classes\database.class.php on line 60
使用我正在使用的查询,mysql_num_rows($ query)应该返回1.
With the query I'm using, mysql_num_rows($query) should return 1. I've googled and checked here, but can't see what I'm doing wrong.
推荐答案
您尚未实际执行查询:
$query = "SELECT username FROM $this->table WHERE username='$sUser'";
$doesFieldExist = false;
// Execute the query with mysql_query()
$result = mysql_query($query);
// $result is a result resource that can be passed
// to mysql_num_rows() unless the query failed and $result is FALSE
if ($result && mysql_num_rows($result) > 0) {
$doesFieldExist = true;
}
这篇关于mysql_num_rows给出错误"mysql_num_rows()期望参数1为资源".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文