I started using PDO recently, earlier I was using just MySQL. Now I am trying to get all data from database.
$getUsers = $DBH->prepare(\"SELECT * FROM use
The PDO
method fetchAll() returns an array/result-set, which you need to assign to a variable and then use/iterate through that variable:
$users = $getUsers->fetchAll();
foreach ($users as $user) {
echo $user['username'] . '
';
}
UPDATE (missing execute()
)
Also, it appears you aren't calling the execute() method which needs to happen after you prepare the statement but before you actually fetch the data:
$getUsers = $DBH->prepare("SELECT * FROM users ORDER BY id ASC");
$getUsers->execute();
$users = $getUsers->fetchAll();
...