Re: Bug or newbie stupidity?
Simon Waters wrote:
Error message syntax question.
Not vitally important, but enquiring minds want to know.
Why does;
----------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
my
$dbh=DBI->connect("dbi:Pg:dbname=dbname;host='mercury';port=5432;",,"dbuser","dbpass",);
----------------------------------------------------------------------------------------
think my server name is "8'@@" (or other random junk) on Debian Sarge
installs (all of mine).
----------------------------------------------------------------------------------------
DBI connect('dbname=dbname;host='mercury';port=5432;','dbuser',...)
failed: could not connect to server: 8´@@
Is the server running on host "mercury" and accepting
TCP/IP connections on port 5432?
at perl/con line 6
----------------------------------------------------------------------------------------
I don't know if you found an solution yet or if you figured it out yourself.
But, it seems to me that the error doesn't make any sense.
However, reading the perldoc I noticed that they don't consider using the (')
when naming servers. I can't find any use of this in examples or my own code.
Looking at my own use of the Pg database:
my $database = $cfg->{db_name};
my $user = $cfg->{db_user};
my $pass = $cfg->{db_pass};
my $host = $cfg->{db_host};
my $server = "database=$database;host=$host;port=5432";
my $datasource = 'dbi:Pg:' . $server;
my $dbh = DBI->connect( $datasource, $user, $pass,
{ AutoCommit => 1, RaiseError => 1 } );
I first difference I notice is the term "dbname" instead of "database".
I would recommend breaking this up into a list of variables instead of pushing
everything into a hard coded string. Perhaps for testing, but nothing beyond that.
Reply to: