Link to home
Start Free TrialLog in
Avatar of JaimeJegonia
JaimeJegoniaFlag for United States of America

asked on

PERL INSTALLATION

I want to connect to mysql using Perl DBI with the following data and code. Oh, by the way I'm using xampp for linux. I've tried to save it on /opt/lampp/htdocs folder, compile it and run it on http://localhost/test.cgi no errors occured but it doesn't print anything except "duhh" on a blue background:-/. I can't connect to mysql...:-( why? Can anybody help me solve this problem?
 
By the way i failed to install DBD:mysql... An error message "can't find mysql.h" was displayed. I tried to locate it using "locate" i cant indeed find this file.. Where could I get this file? Is this related to my problem above?? (DBI installation was, on the other hand, successful)
 
database_name:adventure
user: root
password: sithas
host: localhost
tablename: participant
 
<------------------------------code---test.cgi--------------------------------->
#!/usr/bin/perl

use warnings;

use CGI::Pretty;

use strict;

use DBI();

my $cgi = new CGI;

print $cgi->header();

print $cgi->start_html(

-tilte=>'try',

-bgcolor=>'blue'

);

print "duhh!";

my $dbh = DBI->connect("DBI:mysql:database=adventure;host=localhost","root","sithas", {'RaiseError' => 1});

print "ad";

my $sth = $dbh->prepare("SELECT * FROM participant") or die "query failed";

$sth->execute();

print "sulod";

while (my $ref = $sth->fetchrow_hashref()) {

print "good";

}

$sth->finish();

$dbh->disconnect();

print $cgi->end_html();
<-------------------------------------------end-------------------------------------------->
SOLUTION
Avatar of wlfs
wlfs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FishMonger
Without DBD::mysql, your script won't be able to connect to a mysql database.  What method did you use to install DBD::mysql?  I find it easiest to install it via cpan.

from the command line:

perl -MCPAN -e 'install DBD::mysql'
Avatar of Tintin
Tintin

What Unix/Linux version are you using?

Is mysql installed?

How did you try to install DBD::mysql?
Avatar of JaimeJegonia

ASKER

wlfs,
i've tried it, but the module is not available on CPAN
"The module DBD::mysql isn't available on CPAN"

I also tried to download and installed DBD:: mysql but there was an error "mysql.h could not be found"

FishMonger,
i try to ran this commands but an error occurred "syntax error at -e line 1, near " }) ", execution of -e aborted"
Tintin,
I'm using Ubunto.

i've downloaded DBD-mysql-2.9004 and then extracted it. but when i try to run "perl Makefile.PL" error ocurred "mysql.h could not be found

what could be the solution for this? please help. thanks!
Mixing up the names... :)

Did you copy-paste the one-liner? There is no syntax error in as far as my perl is concerned :)
This is a "screenshot" of my command line:

sandbox$ perl -MDBI -we 'DBI->connect("DBI:mysql:database=adventure;host=localhost","root","sithas", {RaiseError => 1}) or die($DBI::errstr);'
DBI connect('database=adventure;host=localhost','root',...) failed: Access denied for user: 'root@localhost' (Using password: YES) at -e line 1
What mysql packages do you have installed?
xampp for linux was the mysql package i used
>> "The module DBD::mysql isn't available on CPAN"

Wrong...it is available on cpan.

[root@perlman ~]# perl -MCPAN -e 'install DBD::mysql'
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
  Database was generated on Sat, 15 Apr 2006 11:46:26 GMT
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
  ftp://cpan-sj.viaverio.com/pub/CPAN/authors/01mailrc.txt.gz
Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
CPAN: Compress::Zlib loaded ok
Fetching with LWP:
  ftp://cpan-sj.viaverio.com/pub/CPAN/modules/02packages.details.txt.gz
Going to read /root/.cpan/sources/modules/02packages.details.txt.gz
  Database was generated on Wed, 03 May 2006 23:30:52 GMT
Fetching with LWP:
  ftp://cpan-sj.viaverio.com/pub/CPAN/modules/03modlist.data.gz
Going to read /root/.cpan/sources/modules/03modlist.data.gz
Going to write /root/.cpan/Metadata
Running install for module DBD::mysql
Running make for C/CA/CAPTTOFU/DBD-mysql-3.0002.tar.gz
Fetching with LWP:
  ftp://cpan-sj.viaverio.com/pub/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-3.0002.tar.gz
CPAN: Digest::SHA loaded ok
Fetching with LWP:
  ftp://cpan-sj.viaverio.com/pub/CPAN/authors/id/C/CA/CAPTTOFU/CHECKSUMS
CPAN: Module::Signature loaded ok
WARNING: This key is not certified with a trusted signature!
Primary key fingerprint: 2E66 557A B97C 19C7 91AF  8E20 328D A867 450F 89EC
Signature for /root/.cpan/sources/authors/id/C/CA/CAPTTOFU/CHECKSUMS ok
Checksum for /root/.cpan/sources/authors/id/C/CA/CAPTTOFU/DBD-mysql-3.0002.tar.gz ok
Scanning cache /root/.cpan/build for sizes
DBD-mysql-3.0002/
DBD-mysql-3.0002/ChangeLog
DBD-mysql-3.0002/constants.h
DBD-mysql-3.0002/dbdimp.c
DBD-mysql-3.0002/dbdimp.h
wlfs, yes i copied and pasted the one liner but it doesn't work for me...
Hmm, weird. Don't know which OS you are using. Maybe you have to try different quoting for the shell. Try:

perl -MDBI -we "DBI->connect(qq(DBI:mysql:database=adventure;host=localhost),qq(root),qq(sithas), {RaiseError => 1}) or die($DBI::errstr);"

or

perl -MDBI -we 'DBI->connect(qq(DBI:mysql:database=adventure;host=localhost),qq(root),qq(sithas), {RaiseError => 1}) or die($DBI::errstr);'
>>  i copied and pasted the one liner but it doesn't work for me...

What does "doesn't work for me..." mean?

What error message did you get?

Were you able to get the DBD::mysql module installed?  If you don't have the databse driver for Perl to use, you won't be able to connect to the database.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
linux is cumbersome i really can't install DBD:mysql... i just switch to windows using ActivePerl but thanks for all the help i really appreciate it!