I am using Perl CGI to access a MySQL database in XAMPP with the following code:
#!/xampp/perl/bin/perl -w
use DBI;
print "Content-type:text/html\r\n\r\n";
$database = "mydb";
$host = "localhost";
$port = "3306";
$user = "root";
$pw = "";
$dsn = "dbi:mysql:$database:$host:$port";
print "Trying to connect <br />";
$connect = DBI->connect($dsn, $user, $pw, {RaiseError=>1});
if (defined $connect) {
print "Preparing query <br />";
}
$query = "SELECT * FROM reference WHERE ID = 1742031";
$query_handle = $connect->prepare($query);
$query_handle->execute();
$query_handle->bind_columns(undef, \$pmid, \$popu, \$loc);
while($query_handle->fetch()) {
print "$pmid, $popu, $loc <br />";
}
However I am unable to print out the result to my webpage. I think I am not being able to connect to the database because the "Preparing Query" line is not getting printed. But I can connect to the database and execute this query from the mysql command line. I have no idea what the problem could be.
EDIT: After installing the missing DBD:mysql module, I get a new error: "Can't connect to MySQL server on localhost (10061)". I tried following the suggestions here: MYSQL - Cant connect to MYSQL server on 'localhost' (10061) and everything seems to be fine. I have my mysqld.exe running and I am running mysql as a service. Also, I can connect to the database through the mysql command lineas well as phpMyAdmin, so there should be no privileges issue as I only have a root account.
Please advise. I will be grateful for any help.