Problem storing DB_DataObject result in session
| From: | Joseph Szobody | Date: | Wed, 14 Dec 2005 22:57:47 +0000 |
| Subject: | Problem storing DB_DataObject result in session | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-22252@lists.php.net to get a copy of this message | ||
Folks,
I have no problems storing a DB_DataObject in the session when there is one
result record that has been fetched. However I'd really like to be able to
do a find(), save the DataObject in a session variable, and then later come
back to it and do a while($object->fetch()). For example...
---
require_once 'dbo/Tbl_user.php';
require_once 'dbo/Tbl_customer_contact.php';
session_start();
if(!$_SESSION['dbo']) {
$dbo = DB_DataObject::factory("tbl_user");
$dbo->id_role = 4;
$dbo->find();
$_SESSION['dbo'] = $dbo;
} else {
DB_DataObject::debugLevel(1);
$dbo = $_SESSION['dbo'];
while($dbo->fetch()) {
print_r($dbo);
}
}
---
On the first page load the $dbo object is stored in the session variable. On
the second page load, I was hoping to see the results of the fetch() loop,
but instead I get this error:
obj_Tbl_user: 0: fetched on object after fetch completed (no results found)
Now it works if I call $dbo->find() again right before the while() loop, but
the whole idea is to cache a DB result for use on multiple pages, saving
trips to the database.
How can I achieve this?
Thanks,
Joseph