1
votes

I've just started learning perl. So i am getting introduced to database connectivity here. For this i am using XAMPP server installed on my windows7 machine. Following is a sample piece of code that i have written for testing database.

#!D:\xampp\perl\perl.exe
print " Enter Name : ";
chomp($name=<STDIN>);
print " Enter Age : ";
chomp($age=<STDIN>);

use DBI;

$dbh=DBI->connect('DBI:mysql:test');

$insert="insert into student values ('$name',$age)";
$d=$dbh->prepare($insert);
$d->execute();

$s="select * from student";
$s1=$dbh->prepare($s);
$s1->execute();

while(@v=$s1->fetchrow_array)
{
    print "$v[0] \t $v[1] \n";
}

$dbh->disconnect();

As you might be able to see that i'm using the test database available in the phpmyadmin database. i have created a student table with name and age as columns. But when i run this code in my browser i get the following error.

C:\Users\dellpc\Google Drive\coding\web>perl datab.pl
Enter Name : one Enter Age : 20 install_driver(mysql) failed: Can't load 'D:/xampp/perl/vendor/lib/auto/DBD/mysql/mysql.dll' for module DBD::mysql: load_file:The specified module could not be found at D:/xampp/perl/lib/DynaLoader.pm line 190, line 2. at (eval 4) line 3. Compilation failed in require at (eval 4) line 3, line 2. Perhaps a required shared library or dll isn't installed where expected at datab.pl line 9.

I browsed over Google to find out what this error could mean. It seemed that i was missing a file called libmysql.dll , which i downloaded and copied in the xampp perl/bin and the perl/vendor/.../DBD directory as well but this did not help.

I also tried using older version of XAMPP , the issue still persists. Does anyone has any idea how to fix this? Thanks in advance. :)

Edit 1:

This is the error i get when i try install commands.

> cpan> install DBI 

T/TI/TIMB/DBI-1.634.tar.gz Has already been unwrapped into directory D:\xampp\cpan\build\DBI-1.634-HZNMVR Could not make: Unknown error Running make test Can't test without successful make Running make install Make had returned bad status, install seems impossible

cpan> install DBD::mysql Running install for module 'DBD::mysql'

Running make for C/CA/CAPTTOFU/DBD-mysql-4.033.tar.gz Has already been unwrapped into directory D:\xampp\cpan\build\DBD-mysql-4.033-3pgMhg
'D:\xampp\perl\bin\perl.exe Makefile.PL' returned status 512, won't make Running make test Make had some problems, won't test Running make install Make had some problems, won't installRunning install for module 'DBI' Running make for

1
Does the file 'D:/xampp/perl/vendor/lib/auto/DBD/mysql/mysql.dll' exist? Have you installed DBD::mysql? If so, how did you install it? - Dave Cross
This file was already there. prntscr.com/adhey3 Also i tried using the install command cpan> install DBI cpan> install DBD::mysql It also did not help. - user3386500
Is that the right way to install i.e. using cpan for xampp or should i use something else? - user3386500
Using "cpan" (or "cpanm") seems fine. But it seems that something isn't quite right here. I'm afraid I avoid Windows, so I can't be any more help. - Dave Cross
I appreciate the help , thanks. - user3386500

1 Answers

1
votes

I found a workaround this:

It seems the xampp version of perl is somewhat not ready or has missing files. So i just installed strawberry Perl, and the program ran without any issue. I hope it helps any others who are looking for a fix.