Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Connecting to remote db with DBI

by ferreira (Chaplain)
on Mar 23, 2007 at 20:02 UTC ( #606338=note: print w/replies, xml ) Need Help??


in reply to Connecting to remote db with DBI

It looks like you're making a mistake when building the DSN: constrast yours ("DBI:mysql:$db;host=$host") and the one provided in the documentation of DBD::mysql:

use DBI; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";

You're missing the "database=" before $db.

Replies are listed 'Best First'.
Re^2: Connecting to remote db with DBI
by dana (Monk) on Mar 23, 2007 at 21:16 UTC

    Thank you.

    I needed the 'database=' in the statement. I also had to use the hostname rather than the IP address, however this may be a network issue.

    My final connection code looks like the following:
    my $dsn = "DBI:mysql:database=$db;host=$host";
    my $dbh = DBI->connect( $dsn, $user, $pass, { RaiseError => 1 }) or die ( "Couldn't connect to database: " . DBI->errstr );

      Worked the first try !!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2019-10-22 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?