Ron Eggler wrote:
> J�rgen Exner wrote:
>
>> for(@dbset){
>> my $myDBI = "DBI:mysql:$_ :localhost";
>
> Alright,
>
> Thanks for that but when i try it like this:
> #
> # Open the DB connection
> #
> my @dbset=(xmlparse($nemsconf,"DBNAME"));
> print "DB name: ". xmlparse($nemsconf,"DBNAME")."\n";
> #for(my $count = 0; $count < scalar(@dbset); $count++){
> # my $myDBI = 'DBI:mysql:' . $dbset[$count] . ':localhost';
> for(@dbset){
> my $myDBI = "DBI:mysql:$_ :localhost";
> my $dbh =
> DBI->connect($myDBI,xmlparse($nemsconf,"DBUSER"),xmlpa rse($nemsconf,"DBPASS"))
> or die "Couldn't connect to database: " . DBI->errstr . "\n";
> }
>
> It's telling me only:
> [shell]
> DB name: toronto
> DBI connect('toronto :localhost','root',...) failed: Incorrect database
> name 'toronto ' at ./log_parser.pl line 39
> Couldn't connect to database: Incorrect database name 'toronto '
Remove the space.
my $myDBI = "DBI:mysql:$_:localhost";
And check the value.
print "myDBI=$myDBI\n"; #maybe there's a newline? If so, chomp.
> [/shell]
> eventho i can connect nicely with:
> mysql -u root -p toronto
>
> any idea what could be wrong there?
> I first thought where it says "Couldn't connect to database: Incorrect
> database name 'toronto '" that would be a mistake because of the space at
> the end but when I hardcode "toronto" it is displaaying it the same way. So
> I'm pretty stuck here.
Go back to the basics.
use DBI;
my $myDBI = 'DBI:mysql:toronto:localhost';
my $user = 'someuser';
my $pw = 'somepw';
my $dbh = DBI->connect( $myDBI, $user, $pw )
or die "Couldn't connect to database: " . DBI->errstr . "\n";
If that works then verify the values of $user, $pw, and $myDBI are
what you expect.
|