Hello beckmanel,

From the documentation DBI/Signal Handling and Canceling Operations:

my $failed; eval { local $SIG{ALRM} = sub { die "TIMEOUT\n" }; # N.B. \n required eval { alarm($seconds); ... code to execute with timeout here (which may die) ... 1; } or $failed = 1; # outer eval catches alarm that might fire JUST before this alarm( +0) alarm(0); # cancel alarm (if code ran fast) die "$@" if $failed; 1; } or $failed = 1; if ( $failed ) { if ( defined $@ and $@ eq "TIMEOUT\n" ) { ... } else { ... } # some other error }

I am not able to replicate your code so I can identify the problem but the code bellow works for me:

my $failed; my $seconds = 12; eval{ Config::Simple->import_from("".$path."", \%config) or die Config::Simple->error(); my $dbh = DBI->connect("dbi:mysql::".$config{'MySQL.host'}.":".$co +nfig{'MySQL.port'}."", "".$config{'MySQL.user'}."", "".$config{'MySQL.pass'}."", { 'PrintError' => 1, 'RaiseError' => 1 , 'AutoInactiveD +estroy' => 1 } ) or die "Could not connect to ". $config{'MySQL.host'} .": ". $DB +I::errstr ."\n"; local $SIG{ALRM} = sub { die "db_timeout" }; eval { alarm($seconds); $dbh->do("USE Thanos1983"); # or die "Error: " .dbh->errstr. "\n"; 1; } or $failed = 1; # outer eval catches alarm that might fire JUST before this alarm( +0) alarm(0); # cancel alarm (if code ran fast) die "$@" if $failed; 1; } or $failed = 1; if ( $failed ) { if ( defined $@ and $@ eq "TIMEOUT\n" ) { ... } else { print "Error\n" } # some other error } __END__ $ perl test.pl DBD::mysql::db do failed: Unknown database 'Thanos1983' at test.pl lin +e 30. Error

Also usually when I use prepare() I use it like this:

my $sth = $dbh->prepare("SELECT `ID`, `Y-Values` FROM `".$config{'MySQ +L.table'}."` WHERE 1"); if (!$sth->execute()) { die "Error: ". $sth->errstr ."\n"; }

Update: For login purposes I prefer to use Log::Log4perl.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Timeout Failing by thanos1983
in thread Timeout Failing by beckmanel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.