I'm trying to see the structure of the PDOStatement object returned by my query:
$sql="SELECT co.CompanyId, co.Name, co.Address, co.City, co.State, ctry.NameEnglish, co.PostalCode FROM company AS co LEFT JOIN country AS ctry ON ctry.CountryId = co.CountryId ORDER BY Name;";
$result=$conn->query($sql);
The query works, as I'm able to nest some foreach
statements and display the six rows of data by doing the following.
$firstRow=true;
echo '<table>';
foreach ($result as $rowId => $rowData) {
if ($firstRow) {
echo "<thead><tr><th>Row Number</th>";
foreach ($rowData as $fieldId => $fieldData) {
echo "<th>$fieldId</th>";
}
echo "</tr></thead>";
$firstRow=false;
}
echo "<tr><td>$rowId</td>";
foreach ($rowData as $fieldId => $fieldData) {
$fieldData=str_replace("\n","<br>",$fieldData);
echo "<td>$fieldData</td>";
}
echo "</tr>";
}
echo "</table>";
But I was curious about the internal structure of the object $result
, so I var_dump
'ed it and got this:
object(PDOStatement)#4 (1) {
["queryString"]=>
string(185) "SELECT co.CompanyId, co.Name, co.Address, co.City, co.State, ctry.NameEnglish, co.PostalCode FROM company AS co LEFT JOIN country AS ctry ON ctry.CountryId = co.CountryId ORDER BY Name;"
}
Why doesn't var_dump
show the arrays associated with the rows and fields?