Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem passing the $dbh handle between pages

Status
Not open for further replies.

medine

Programmer
Jun 20, 2002
4
GB
Hi folks,

I would like to be able to pass a DB handle between pages on a web site so that I will be able to use the same db connection. The connection works fine as long as I use it within the same file but when I try to pass the handle to another page I get the following error message.

Can't locate object method "prepare" via package "DBI::db=HASH(0x831cef8)" (perhaps you forgot to load "DBI::db=HASH(0x831cef8)"?) at TransactionDB.pm line 43.

I created the TransactionDB.pm file mentioned in the error message and if works fine.

I use

my $dbh = param('dbh');

to get the handle, which I then pass to a method which works fine elsewhere in the program.

I read somewhere that the DB object gets converted to a string, thats why it does not recognise the object, but I do not know how to maintain the handle as an obect when passing it to another page.

Any thoughts?

Thanks

Cal

 
The $dbh that you are getting back from DBI is a reference to an object held in memory. When the next page is requested, you are trying to access a block of memory that is no longer there, as it is released to the pool as soon as your script finished returning the previous page.

You can have persistent database connections by using mod_perl [1] and the Apache::DBI [2] module.

[1] [2]

Barbie
Leader of Birmingham Perl Mongers
 
Barbie,

OK thanks for your help, I will work round the problem in the meantime and look at implimenting mod_perl eventually.

Cal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top