Jump to content

How to save mysql link resources in the session variable?


deoac

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
Link to comment
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.
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.