SleepyJay has asked for the wisdom of the Perl Monks concerning the following question:
Suppose in my startup.pl for my Apache server I created a global variable, $dbh, and set that to a DBI MySQL database connection (or an Apache::DBI connection if that is better).
Later, a request comes in that runs code that does an insert using that $dbh. Given that I made $dbh global, is last_insert_id (in whichever flavor) valid whatsoever? AFAIK, it is only safe per session, which in this case makes it not safe, correct?
IOW, I would need to create a whole new connection to the database for each request to Apache that wants to insert rows? Or maybe something about how I set up transactions/commits would help me here? These are currently MyISAM tables, but I suppose they don't have to be.
Am I thinking this out correctly? Please someone check my sanity!! :)
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Global dbh and inserts
by McA (Priest) on Feb 19, 2014 at 08:23 UTC | |
|
Re: Global dbh and inserts
by locked_user sundialsvc4 (Abbot) on Feb 19, 2014 at 14:13 UTC | |
by SleepyJay (Beadle) on Feb 19, 2014 at 16:23 UTC |