I can successfully select an object, but I cannot fetch all rows from the database using the following code, can anyone see any obvious errors?
$sql2 = "SELECT ID, Latitude, Longitude, Name FROM Countries";
$stmt2 = $pdo->prepare($sql2);
$stmt2->execute();
while ($row = $stmt2->fetch(PDO::FETCH_ASSOC)) {
echo $countryID = $row->ID;
echo $countryName= $row->Name;
echo $longitude2 = $row->Longitude;
echo $latitude2 = $row->Latitude;
}
$row['key'], not$row->key.PDO::FETCH_ASSOCfetches an assoc array, which you use as an object, usePDO::FETCH_OBJor change$row->IDto$row['ID']. There's also no params in your query, you needn'tprepareit if it really is a hard-coded query string