return one value from database with mysql php pdo

前端 未结 3 767
孤街浪徒
孤街浪徒 2020-11-30 06:19

Im not trying to use a loop. I just one one value from one column from one row. I got what I want with the following code but there has to be an easier way using PDO.

<
3条回答
  •  执笔经年
    2020-11-30 07:07

    You can use fetchColumn():

    $q= $conn->prepare("SELECT name FROM `login_users` WHERE username=?");
    $q->execute([$userid]);
    $username = $q->fetchColumn();
    

提交回复
热议问题