Jump to content

Archived

This topic is now archived and is closed to further replies.

deoac

How to save mysql link resources in the session variable?

Recommended Posts

When I make a mysql connection on one page of my site, I want to save the resource in the $_SESSION variable, and then use the resource on the next page.

Unfortunately, after a session_start, the mysql resource is gone.

Other variable types are saved properly in the $_SESSION.

Any ideas on how I can accomplish this?

Thanks,
Shimon

Share this post


Link to post
Share on other sites
I'm not quite clear on why you would want to re-use the same resource. It's not going to contain the same recordset if that's what you're trying to do.

Besides, you have to reconnect to the database on the new page, so it can't re-use the same identifier.

Share this post


Link to post
Share on other sites
If you want to do something like that then use a persistant connection mysql_pconnect

However with a persitant connection you are in danger of hitting your maximum database connections limit, therefore your site goes down until all the persistant connections are closed.

Share this post


Link to post
Share on other sites
Resource objects (ie connections) cannot be safely serialized and thus cannot be saved in sessions. Why you would ever want to try this in the first place is behond me, it is an invaluable waste of resources.

Share this post


Link to post
Share on other sites
Thanks for everyone's assistance. My goal is to not have to reconnect to the mysql server on every page. We've don't want to be limited to a small number of persistent connections.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.