Jump to content


How to save mysql link resources in the session variable?

  • Please log in to reply
4 replies to this topic

#1 deoac

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 May 2006 - 03:16 PM

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?


#2 ober

  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 10 May 2006 - 03:23 PM

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.

Info: PHP Manual

#3 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 May 2006 - 04:27 PM

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.

#4 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 11 May 2006 - 12:17 AM

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.

#5 deoac

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 May 2006 - 12:45 PM

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.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users