3000 explained code solutions for 75 technologies

php-pdoFetch array of column values with PHP PDO

$st = $pdo->prepare('SELECT id FROM test');
$cols = $st->fetchAll(PDO::FETCH_COLUMN);ctrl + c

prepare given query to execute


column we want to get into resulting array


run query on the server


returns all rows from result set


will return single column value per row rather than associative array


resulting array of column values