Hie, I am learning how to use PHP,and have followed everything in the tutorials I am watching to the letter but I don't understand why I am getting an error. Here is my code:
<?php
try {
$db = new PDO("mysql: host = localhost; dbname = tutorialdb", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$db->exec("SET NAMES 'utf8'");
} catch(Exception $e) {
echo "Could not connect to database.";
exit;
}
try {
$results = $db->query("USE mydatab; SELECT name, price, img FROM products ORDER BY sku asc");
} catch (Exception $e) {
echo "Could not retrieve data.";
exit;
}
echo "<pre>"
var_dump($results->fetchAll(PDO::FETCH_ASSOC));
?>
Any positive input will be greatly appreciated, thank you.