PHP PDO returning single row

Just fetch. only gets one row. So no foreach loop needed 😀

$row  = $STH -> fetch();

example (ty northkildonan):

$id = 4;
$stmt = $dbh->prepare("SELECT name FROM mytable WHERE id=? LIMIT 1"); 
$stmt->execute([$id]); 
$row = $stmt->fetch();

Leave a Comment