3000 explained code solutions for 75 technologies


php-pdoFetch single row with PHP PDO


$st = $pdo->prepare('SELECT * FROM test LIMIT 1');
$st->execute();
$row = $st->fetch(PDO::FETCH_ASSOC);ctrl + c
$pdo->prepare

prepare given query to execute

$st->execute(

run query on the server

fetch

returns single row from resulting set

FETCH_ASSOC

will return row as an associative array (rather than numbered array)