I'm trying to print data from my SQL table, but there is something wrong, or something I don't get.
Depending on which tutorial I am following certain commands simply just don't work for me.
In this example, I should write;
try{
$opendb = NEW PDO('mysql:host=$dbhost;dbname=$dbname','$dbuser','$dbpass');
}catch(PDOException $e){
die($e->getMessage());
}
$result = $opendb->query("SELECT * FROM quiz");
$all = $result->fetchAll();
echo "<pre>";
print_r($all);
But I couldn't get it working no matter what I tried. I think it might be the mysql -> commands that isn't working for me? But I am not sure. I rewrote the example with code I've been using earlier so it looked like this:
$opendb = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die(mysqli_error($opendb));
$result = mysqli_query($opendb, "SELECT * FROM quiz");
$all = mysqli_fetch_all($result);
echo("<pre>");
print_r($all);
This one works just fine.
I'm in the process of learning and I have no idea why the given example isn't working but it does exactly what it should when I use mysql_command() instead of ->command.