As I am working through the book, I am finding small errors. I didn't see this posted anywhere so I thought that I would post it here.
On page 131, the code for dbtest.php incorrectly loops over the $arRowHash:
PHP Code:
$objHandle = pg_connect("host=localhost port=5432 dbname=chaptersix user=chaptersix password=chaptersix");
if (!$objHandle) {
echo "An error occurred connecting.\n";
exit;
}
$objResult = pg_query($objHandle, "SELECT * FROM \"user\"");
if (!$objResult) {
echo "An error occurred querying.\n";
exit;
}
$arRowHash = pg_fetch_all($objResult);
print "Number Of Rows: ".count($arRowHash)."\n";
// ----------------------------------------------------------------------------
// The error is here....
//
// The for loop would never execute since the
// variable $i would never be larger than the count of
// the variable $arRowHash.
//
// Should be
// for ($i = 0; $i <= (count($arRowHash) - 1); $i++
//
// Notice that changed the conditional so that the for
// loop would execute until the variable $i is larger
// than the count of $arRowHash minus one.
// -----------------------------------------------------------------------------
for ($i = 0; $i >= (count($arRowHash) - 1); $i++) {
print "Row $i\n";
foreach ($arRowHash[$i] as $key => $value) {
print " - Column $key, value $value<br />\n";
}
}
pg_close($objHandle);
Enjoy....
