When I try to work with DBI(latest), CGI(latest), Apache(2.2.14) and
MySQL(5.0), Perl 5.10 together in Windows, I get the below problem for
DBI connect.
connect('database=:host=','',...) failed: Access denied for user
'ODBC'@'localhost' (using password: NO).
However, I am able to connect to mysql by root id on command prompt
directly & also throw a normal script without CGI. However CGI as such
no problem. It only gives problem when CGI tries to connect to DB.
File t.cgi content,
use DBI;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
my ($db, $host, $user, $pswd, $tbl) = param(); # cgi function.
my %f;
foreach my $p (param()) {
$f{$p} = param($p);
}
#connect to MySQL database
my $dbh = DBI->connect (
"DBI:mysql:database=".$f{$db}.":host=".$f{$host},
$f{$user},
$f{$pswd},
{ RaiseError => 1, AutoCommit => 0 }
)
or die "Can't connect to database: $DBI::errstr\n";
#prepare the query
my $sth = $dbh->prepare( "SELECT * FROM ".$f{$tbl})
or die "Cannot select from table :: errstr\n";
#execute the query
$sth->execute( );
# Retrieve the results of a row of data and print
print header;
print start_html("MySql DB query result");
while ( my @row = $sth->fetchrow_array( ) ) {
print "@row\n<br>";
}
print end_html;
warn "Problem in retrieving results", $sth->errstr( ), "\n"
if $sth->err( );
#disconnect from database
$dbh->disconnect or warn "Disconnection error: $DBI::errstr\n";
exit;
Thanks/Regards,
Ashok