Re: DB connect object in session
| From: | Justin Patrin | Date: | Thu, 21 Jul 2005 16:05:43 +0000 |
| Subject: | Re: DB connect object in session | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20089@lists.php.net to get a copy of this message | ||
On 7/21/05, Tom Rogie <Tom@rogie.be> wrote:
> Hello,
>
> For a project with lots of database access, I planned to put the
> DB:connect object into a session.
>
> I only have one problem: before I start the session, the classes from
> the project must be defined _and_ also the DB object must be connected (
> DB::connect( $db ) ) else I get PHP incomplete class object errors.
> So I cannot check the isset of my $_SESSION["db"] variable before I do
> connect to the database... Means that I have to connect to the database
> on every click?
>
> Is there a way to keep using the same database object through the session?
>
Storing a DB object in a session won't work. The connection to the
database is a special kind of variable called a "resource". Same as
for writing to and reading from files and sockets. You can't put these
in a session as once the request is finished the resource is closed.
You'll need to do a DB::connect on every request.
--
Justin Patrin