Fetch Results Array with PDO in PHP

<?php 
    $con = new PDO('mysql:host=localhost;dbname=yourdb', 'root', '');
    $stmt = $con->prepare('select * from product');
    $stmt->execute();
    while ($product = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo 'id: ' . $product['id'] . '<br>';
        echo 'name: ' . $product['name'] . '<br>';
        echo 'price: ' . $product['price'] . '<br>';
        echo '-------------------<br>';
    }
?>