$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password"); $query = $pdo->query("SELECT * FROM mytable"); $result = $query->fetchAll(PDO::FETCH_ASSOC); print_r($result);
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password"); $query = $pdo->query("SELECT * FROM mytable"); $result = $query->fetchAll(PDO::FETCH_OBJ); foreach($result as $row) { echo $row->name."This code fetches all the rows from the "mytable" table in the "mydatabase" database, and returns an array containing all the rows as objects. The code then loops through the array and prints the name field of each row to the screen. The package library for this function would be PHP PDO Extension.
"; }