I get no results returned with this PHP postgreSQL PDO statement. I expected to see several rows. What have I done wrong? How can I retrieve them and put them into an object or array?
$sth = $dbh->prepare('SELECT * FROM address');
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
while($row = $sth->fetch()) {
echo $row['StreetAddress1'] . "\n";
}
Consider the result set a stack, and each fetch() call pops off a result row. You’ve called fetch once OUTSIDE of the while loop, and then apparently thrown away $result. That means one row of result data is gone. As for putting them into an object/array, that’s up to you. could be as simple as:
inside the loop.
either