d
Amit DhamuSoftware Engineer
 

Simple Select Query with PDO

1 minute read 00000 views
$connection = new PDO("mysql:host=localhost;dbname=database1", $username, $pass);

$select_books = $connection->query('SELECT * FROM books');

// Num of records
$select_books->rowCount();

// Associate array of all results
$select_books->fetchAll();

// To loop through the results
while ($books = $select_books->fetch()) {
    echo $books['title'] . '
';
}