next()期望参数1为数组,给定布尔值

时间:2017-06-13 18:50:42

标签: php mysqli

我正在尝试为我的项目创建一个登录系统,但在登录期间发生了错误。错误说'next()要求参数1为数组,布尔值为'。

public function login(Customer $c) {
        $sql = "select * from customer where username = ? and password = ?";

        try {
            $username = $c -> getUsername();
            $password = $c -> getPassword();

            $stmt = $this -> getConnection() -> prepare($sql);
            $stmt -> bind_param('ss', $username, $password);
            $res = $stmt -> execute();

            while (next($res)) {//error occurred on this line
                return true;
            }

        } catch (SQLiteException $ex) {
            echo $ex;
        }

        return false;
    }

1 个答案:

答案 0 :(得分:4)

execute()成功时返回true,失败时返回false。

像这样使用:

$stmt->execute();
while($row = $stmt->fetch_assoc())
{
    return true;
}