I've used PHP's mysql and mysqli procedural code for years, but I'm trying to learn how to use OOP. One of the simple projects I'm working on needs to return records from a MySQL database, but so far I'm not getting the results I expected.
I have a database in place with several tables, one of which is
MtgsCities. I have used this database and table successfully in the past, and I have checked to confirm that it still holds 43 records, with only one field (of varchar(24) type) in each record. That solitary field is
mtgCity.
Having established a connection handler (
$cnxn), I run the following four lines of code:
Code:
foreach ($cnxn->query("SELECT * FROM MtgsCities") as $row);
{
echo "The city is " . $row["mtgCity"] . ".<br />";
}
The result prints out only one line:
Quote:
The city is Worthington Springs.
|
Clearly the routine is reading the table, but is displaying only the last record in the table. I'm obviously missing something, but all the online searching I've done has not revealed anything helpful.
Any ideas where I can go from here?