Codice PHP:
try{
//preparo la query
$res $DB->prepare('SELECT id FROM user;');
//la eseguo
$res->execute();
  while(
$row $res->fetch(PDO::FETCH_OBJ)){
    echo 
$row->id;
  }
  
$res null;
//col catch verifico eventuali errori
}catch(PDOException $e){
  echo 
$e->getMessage();