in reply to DBD::mysql connections

How long does it normally take this script to run? I've never run into a database connection timeout situation before. If you can, briefly describe what this script did *before* you changed it to connect every time you call a function - did it connect, then do lots of database stuff, and then close the connection, or are there gaps of time in between when there is no database interaction?

Seems like an enormous waste of time to connect (and disconnect) to the database in every function!! There's got to be a way around that. The 'ping' solution is a step in the right direction, and that may be the best solution. Ping is designed to be very fast and efficient - you should only need to re-connect if ping is unsuccessful.

Also, as someone else already pointed out, it's very inefficient and wasteful to put the db connection parameters in more than one place. You should create a myConnect (or whatever) subroutine and in that subroutine do your dbi connect and return the resulting database handle ($dbh) to the caller. In that subroutine put the connection parameters so that you have them just in one place. That way if your connection parameters change, you only need to change them in one place.

HTH.