Search code examples
phpmysqlpdofetchfetchall

Does fetchAll fetch ALL? :)


Simple question really.. If I have this:

$sql = 'SELECT id, name, address, city, phone FROM users';
$STH = $conn->query($sql);

$row = $STH->fetchAll();

if (count($row) > 0) {

    $id = $row[0]['id'];

}

Will fetchAll ignore what I specifically chose to select and instead select EVERYTHING from the row, including large text fields etc.?

If so, what could be a workaround? I also need the row count


Solution

  • Fetch all simply means "fetch all rows into an array". It does not mean "fetch all columns, also the ones which I did not select" since this would be a quite awkward behaviour.

    So, no, you need no workaround.