in reply to DBD::mysql connections
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.
|
|---|