return one value from database with mysql php pdo

You can use fetchColumn():

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

Leave a Comment