http://qs321.pair.com?node_id=811946


in reply to storing database handle object in a variable

You may be trying to do this:

  1. Get a $dbh.
  2. Store the $dbh in a file on disk or something.
  3. Retrieve the $dbh and use it in a program other than the one that got it in the first place.

If that's your goal, you're sunk. The $dbh is not a mere piece of data like an account number or the text of the Camel book that you can write and read back later. Instead, it is an object holding an open socket to a database. The network connection that has been opened can't be serialized for later.

If you want to use the same connection to a database in two places concurrently, you're still sunk. Only one process can use a connection at a time. To get that behavior, you'd have to have a process that connects to the database and then acts as a traffic cop for other processes that want to use the connection. In that case, you might as well have the other processes connect directly.

If what you want to do is open a connection to a database and then start another program that uses that connection, you can sort of do that. Have a look at DBI, fork, and clone. for a way to go.

But really, why do you want to do this? What is the problem you face that causes you to seek this solution?