Posted by ZeldorBlat on 12/06/05 02:08
>Especially a database connection is not something I would store between
>sessions. There is a major chance that the client does not come back
>(every website visitor leaves at SOME point) and you would end up
>keeping connections open that are not used anymore.
You can't store a database connection (well, the resource that is the
link) in a session anyway. Sessions can only store data that is
serializable, of which resources are not. If you have a class for your
database you can define the __sleep() and __wakeup() methods to
open/close the actual link when the object is serialized/unserialized.
If you want to share actual database connections among requests, the
best you can probably do is use mysql_pconnect() instead of
mysql_connect(). pconnect will check for an open link to reuse before
trying to make a new one. At the end of the request the connection is
left open. Be careful though...unless you really have a reason to use
pconnect() I'd stay with plain connect().
[Back to original message]
|