mysql - PHP PDO Fetch not working? -
i can select object, cannot fetch rows database using following code, can see obvious errors?
$sql2 = "select id, latitude, longitude, name 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; }
the parameter pdo::fetch_assoc tells pdo return result associative array. can fetch array not object
while ($row = $stmt2->fetch(pdo::fetch_assoc)) { echo $countryid = $row['id']; echo $countryname= $row['name']; //rest of code }
Comments
Post a Comment