PHP的PDO查询不返回结果

时间:2019-12-03 16:42:59

标签: php sql pdo

问题与以下代码有关

if(isset($_SESSION["username"])){
    $username = $_SESSION["username"];
    $sql = "SELECT * FROM users WHERE username = $username";
    $stmt = $connect->link->query($sql);

    while($row = $stmt->fetch()){
        $first = $row["first_name"];
        $last = $row["last_name"];
        $email = $row["email"];
        $role = $row["role"];
        $username = $row["username"];
        $status = $row["status"];
    }
}

返回以下错误

Fatal error: Uncaught Error: Call to a member function fetch() on boolean in C:\wamp64\www\cms\CMS_TEMPLATE\admin\profile.php on line 12

我只能假定问题是在sql语句中引用变量的方式吗?

0 个答案:

没有答案