First of all I am new to PDO, just started working with it a week ago.
I'm trying to load the website configuration out of the database, and echo it on the page, however, any table/field result displays twice while I only need one.
This is the code
function config() {
global $db;
try {
$sql = "SELECT id, name FROM config";
$stmt = $db->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row['id'];
} catch (PDOException $e) {
echo '<pre>';
echo 'Line: ' . $e->getLine() . '<br />';
echo 'File: ' . $e->getFile() . '<br />';
echo 'Error Message: ' . $e->getMessage();
echo '</pre>';
}
}
Now when I echo the $row['id']; or $row['name']; it will display twice on the page, while it only needs to be shown once.
Is there anything that I am doing wrong?