Amit Dhamu

Writes Code

Simple Select Query with PDO

$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']."<br/>";
}


mysql / query / select / pdo

← Query Fetch Types in PDO CRUD Functions with PDO →