Good Afternoon!
I have made a connection class to a Microsoft Access Database (which works). However my problem lies where I\'m trying to use this class to execute a
ini_set('display_errors', '1');
include_once '\classes\connectionClass.php';
$con = new connection();
$pdoConnection = $con->connect();
$data = $pdoConnection->query("SELECT * FROM celebs")->fetchAll();
foreach ($data as $row) {
echo $row['firstname'];
echo $row['surname'];
}
this is all the code you need.
$result is just a boolean that indicates whether the query was successful or not. The fetchAll method is on PDOStatement, so it should be:
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
You're also executing the statement wrong, it should be:
$result = $sql->execute();
The method you used is for executing a SQL string without first preparing it. You could instead do:
$result = $pdoConnection->exec("SELECT * FROM celebs");
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {