Try like this, this my code snippet I have used long before,
// PDO
$pdo = new PDO('mysql:dbname=test;host=127.0.0.1', 'example', 'example');
print '<h3>PDO: simple select</h3>';
foreach($pdo->query( 'SELECT * FROM users;' ) as $row)
{
//Fetching data
}