For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > July 2005 > Re: [PEAR] DB connect object in session









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] DB connect object in session
Justin Patrin

2005-07-24, 8:39 pm

On 7/21/05, Tom Rogie <Tom@rogie.be> wrote:
> Hello,
>=20
> For a project with lots of database access, I planned to put the
> DB:connect object into a session.
>=20
> 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?
>=20
> Is there a way to keep using the same database object through the session=

?
>=20


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.

--=20
Justin Patrin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com