Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: storing database handle object in a variable

by kyle (Abbot)
on Dec 09, 2009 at 15:25 UTC ( #811946=note: print w/replies, xml ) Need Help??

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?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://811946]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2021-08-06 00:05 GMT
Find Nodes?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)

    Results (44 votes). Check out past polls.