I'm trying to write my first portable PHP application using PEAR's DB.php functions. I understand that my queries are being stored in objects (as instances of the DB class), but I can't seem to find a method that will allow me to reset a result. Here's what I'm trying to do...the call to the non-working reset() function is near the end, everything else is working fine....
// connect to the database using the PEAR DB.php abstraction layer so our code will be nice and portable.
// All the variables we're using here are defined in the config.inc.php file.
$dbh = DB::connect("$pear_db_identifier://$db_username:$db_password@$db_hostname/$db_database_name");
// set default mode for all resultsets
// to return an associative array with column names as keys.
$dbh->setFetchMode(DB_FETCHMODE_ASSOC);
// execute query and save the result in an object
//$query = "SELECT * FROM ".$db_prefix."pages ORDER BY page_number ASC";
//$result = $dbh->query($query);
$query = "SELECT * FROM digital_subscription_customers WHERE login='$login' AND productid='999'";
$result = $dbh->query($query);
//if we find more than one course, the user must have registered more than once, so
//generate an error...
echo "<br><b>Checking to see if you are properly registered...</b><br>";
$numrows=$result->numRows();
switch($numrows){
case ($numrows <= 0):
echo "Nope...we could not find a course with your user info. Please contact support if you are sure you're registered.<br><br>";
exit;
case ($numrows == 1):
echo "Yep...you appear to be registered exactly once for this course. Now proceeding to check for saved sessions...<br><br>";
break;
default:
echo "You seem to be registered more than once. We need to correct this problem before you may proceed with your online training.<br><br>";
break;
}
// Now let's load up the data and then get any session info...
if($row = $result->fetchRow()){
getSessionData($row);
}else{
echo "There was no data in the result set!!!!";
}
// iterate through rows and print column data
//first reset the $result so we don't end up printing nothing...
reset($result);
while($row = $result->fetchRow())
{
foreach($row as $k=>$v){
echo "<b>$k - </b>$v";
}
echo "<br>";
}
So basically I just need to know how to reset my $result object so that I can loop through it again and display the results. I suspect I'm just approaching this slightly wrong...there must be a PEAR function I don't know about somewhere. Anyone have a clue?