I'm using XAMPP and phpMyAdmin to create local databases. Here's my PDO code to try to display some tables
<?php
$pdo = new PDO('mysql:host=localhost;dbname=puppies', 'admin','puppies');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$result = $pdo->query('SELECT `puppy_name`, `breed_name`, `description`, `price` FROM `animals`, `breeds` WHERE `animals` . `breed_id` = `breeds` . `id`');
}
catch (PDOException $e) {
echo $e->getMessage();
}
foreach ($result as $puppy) {
$puppy[`puppy_name`]
$puppy[`breed_name`]
}
?>
I keep receiving this error:
Parse error: syntax error, unexpected '$puppy' (T_VARIABLE) in /Applications/XAMPP/xamppfiles/htdocs/cs4ww3/invalid.php on line 12
I'm pretty sure I'm connecting properly - if I remove the foreach
loop then I get a blank screen with no errors.
";` might get you started on what you want! @NicholasHassan – Qirel Nov 20 '16 at 22:31