Cannot use object of type PDOStatement as array

后端 未结 2 1131
日久生厌
日久生厌 2021-01-22 05:49

I want to check if some column of specify user is holding a value higher than 0.

Problem

When doing the query, and then executing it

2条回答
  •  暖寄归人
    2021-01-22 06:20

    try this:

    $sql = "SELECT * FROM admin WHERE username = ?";
    $stmt = $CONNECT_TO_DATABASE->prepare($sql);
    $stmt->execute(array($_SESSION['user']));
    $admin = $stmt->fetch();
    if($admin) {
       //do something if query returns row(s)
    }
    

提交回复
热议问题