Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PERL INSTALLATION

Posted on 2006-05-03
15
Medium Priority
?
538 Views
Last Modified: 2012-05-11
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-------------------------------------------->
0
Comment
Question by:JaimeJegonia
  • 5
  • 5
  • 3
  • +1
15 Comments
 
LVL 5

Assisted Solution

by:wlfs
wlfs earned 800 total points
ID: 16602274
Well, the first thing to do here is to look for the error message caused by the connect statement.
At the command prompt type

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

Maybe the error message is enough information to solve the problem. If it isn't post the result here.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 16602278
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'
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16602452
What Unix/Linux version are you using?

Is mysql installed?

How did you try to install DBD::mysql?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:JaimeJegonia
ID: 16602491
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"
0
 

Author Comment

by:JaimeJegonia
ID: 16602535
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!
0
 
LVL 5

Expert Comment

by:wlfs
ID: 16602537
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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 16602556
What mysql packages do you have installed?
0
 

Author Comment

by:JaimeJegonia
ID: 16602624
xampp for linux was the mysql package i used
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 16602629
>> "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
0
 

Author Comment

by:JaimeJegonia
ID: 16602630
wlfs, yes i copied and pasted the one liner but it doesn't work for me...
0
 
LVL 5

Expert Comment

by:wlfs
ID: 16604483
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);'
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 16606787
>>  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.
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 1200 total points
ID: 16608216
If the installation of the DBD::mysql module is still giving an error related to the missing mysql.h file, you may want/need to reinstall mysql by compiling it from source.

If never used xampp, but since it's installing a combined (binary) package of apache, mysql, php, Perl, and a couple other items all with a single tar command, it's making a lot of compromises and sacrifices for the sake of convenience.  One of these sacrifices is the missing mysql.h file.
0
 

Author Comment

by:JaimeJegonia
ID: 16612308
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!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question