|Don't ask to ask, just ask|
Global dbh and insertsby SleepyJay (Beadle)
|on Feb 19, 2014 at 01:28 UTC||Need Help??|
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!! :)