当我运行mysql_num_rows
查询以检查用户名是否已在我的php文件中注册时,收到错误。
Warning: mysql_num_rows() expects parameter 1 to be resource, string given
in C:\xampp\htdocs\system\class.database.php on line 22
这是我的代码......首先是我的nameTaken
函数,我运行行函数...
public function nameTaken($username)
{
global $database;
if ($database->rows("SELECT COUNT(*) FROM users WHERE username = '" . $username . "' LIMIT 1") > 0)
{
return true;
}
return false;
}
以下是我在数据库类中的连接方式
public function connect()
{
global $config;
$this->connection = mysql_connect($config['db']['host'], $config['db']['user'], $config['db']['pass']);
mysql_select_db($config['db']['name'], $this->connection);
}
这是行函数
public function rows($command)
{
echo 'ROWS IS BEING CALLED BY ' . $command;
$result = mysql_query($command);
$rows = mysql_num_rows($command);
return $rows;
}
为什么我在运行mysql_num_rows
时收到错误?
答案 0 :(得分:2)
您需要将结果资源传递给mysql_num_rows
。将$rows = mysql_num_rows($command);
更改为$rows = mysql_num_rows($result);