in reply to DBD::mysql connections

If you can assume that these database methods run queries often enough to keep the dbh open (as you are doing in you example), you can also try this:
sub getNullEndIds{ my $self = shift; my $dbh = shift; $dbh = DBI->connect($dbi,"monster_mirror","m1rr0r",{'RaiseError' = +> 1}) unless $dbh->ping; # rest of method # don't close the dbh at the end of this method }
And check the DBI docs for the ping() method.

Actually I'd wrap the DBI->connect call in a seperate sub, so you don't have to put your connection info all over the place.

Replies are listed 'Best First'.
Re^2: DBD::mysql connections
by seaver (Pilgrim) on Jun 17, 2004 at 15:25 UTC
    fantastic, only create a connection if it's failed, good call.

    But you highlighted something: If you can assume that these database methods run queries often enough

    is there then, basically, a time limit to how long an idle connection stays open? and can that time limit be modified?

    Cheers
    Sam

      If you're using MySQL, check out the variables wait_timeout and interactive_timeout

      query: 'show variables' to see the current values. (they are in seconds). I think my default wait_timeout is 15 minutes.
        well it seems both 'wait_timeout' and 'interactive_timeout' are '28800' seconds, which is 8hours! I think that's enough time :-D

        S