Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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?


Comment on Re: storing database handle object in a variable
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-12-21 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls