The fetch method is missing.
For example, you can extract the data like this:
$statement = $db->query('SELECT name FROM order'); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { echo $row['name'] . "\n"; }
All records can also be fetched using the fetchAll method.
Well, to add an exception for errors would be nice:
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Total, the following code will turn out:
try { $db = new PDO('mysql:host=localhost;dbname=table','root','12345'); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $statement = $db->query("SELECT * FROM order"); foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $item) { echo $item['name'] . <br>; } } catch (PDOException $e) { // Обработка исключений... }