Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Perl DBI Question

by twerq (Deacon)
on Jan 21, 2004 at 21:48 UTC ( [id://323030]=note: print w/replies, xml ) Need Help??


in reply to Perl DBI Question

You might want to look at the "RaiseError" section of the DBI manual, I think this is what you're looking for.

$dbh = DBI->connect($dsn, $user, $password, { RaiseError => 0, AutoCommit => 0 });

--twerq

Replies are listed 'Best First'.
Re^2: Perl DBI Question
by Coruscate (Sexton) on Jan 21, 2004 at 22:34 UTC

    Close, but not what the OP was asking for. That will automatically die if the connection fails. Either what pg provided or something like the following would be more of a workable solution:

    #!c:/perl/bin/perl -w $|++; use strict; use DBI; my $table = 'table_name'; my @db = ( ['localhost', 'user1', 'pass1'], ['other.server.com', 'user2', 'pass2'], ['last.attempt.com', 'user3', 'pass3'], ); my $dbh; for my $db (@db) { eval { $dbh = DBI->connect( 'dbi:mysql:database=' . $table . ';host=' . $db->[0], $db->[1], $db->[2], { AutoCommit => 1, RaiseError => 1 } ); }; next if $@; } die "Unable to connect to any database!\n" if not defined $dbh;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://323030]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-06-15 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.