我有一个mysql查询,我用来登录数据库,但由于某种原因它返回-1,即使我输入正确的值并且相同的查询执行时没有bind_param
$username = $_POST['username'];
$password = md5($_POST['password']);
$user_array = array('username' => $username,'password' => $password );
$queryname = "SELECT username, password FROM user WHERE username = ? AND password = ?";
function auth($queryname,$user_array) {
$stmt = $this->connection->prepare($queryname);
$stmt->bind_param('ss', $user, $pass);
$user=$user_array['username'];
$pass=$user_array['password'];
$stmt->execute();
return $stmt->affected_rows;
}
有关如何调试此内容的任何建议吗?
答案 0 :(得分:1)
$stmt->affected_rows
returns the total number of rows changed, deleted, or inserted:
此功能仅适用于更新表的查询。要从SELECT查询中获取行数,请改用mysqli_stmt_num_rows()。
将return $stmt->affected_rows;
更改为:
$stmt->store_result();
$count = $stmt->num_rows;
$stmt->close();
return $count;