By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,661 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,661 IT Pros & Developers. It's quick & easy.

trying to connect to DB

P: 35
i've been trying to connect to a db using this code:
Expand|Select|Wrap|Line Numbers
  1. #!"C:\xampp\perl\strawberry\perl\bin\perl.exe"
  2. use DBI;
  3.  use strict;
  4.  use warnings;
  5.  
  6. print "Content-type: text/html \n\n"; #HTTP HEADER
  7. my $dbh = DBI->connect("DBI:mysql:survey","root","") or die "Couldn't connect to database: " . DBI->errstr;
but it does not work, i dont get the die error message only this default xampp error :
Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
Expand|Select|Wrap|Line Numbers
  1. Premature end of script headers: DB.pl
  2.  
  3. If you think this is a server error, please contact the webmaster.
  4. Error 500
  5. localhost
  6. 12/06/09 11:00:53
  7. Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i mod_autoindex_color PHP/5.2.8 
Dec 6 '09 #1
Share this Question
Share on Google+
11 Replies


Expert Mod 100+
P: 589
Did you check the apache error log?

It's probably due to your shebang line. Try changing it to this:
Expand|Select|Wrap|Line Numbers
  1. #!C:/xampp/perl/strawberry/perl/bin/perl.exe
Dec 6 '09 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
Unfortunately, I don't have any experience with xampp, so I am not aware of the caveats.

I guess my first question is, can you connect to the database manually from the command line? If not, what does it tell you?

Regards,

Jeff
Dec 6 '09 #3

Expert Mod 100+
P: 589
I just noticed that you have a syntax error in the error handling portion of the connect statement.
Expand|Select|Wrap|Line Numbers
  1. DBI->errstr
should be
Expand|Select|Wrap|Line Numbers
  1. $DBI::errstr
Try this version:
Expand|Select|Wrap|Line Numbers
  1. #!C:/xampp/perl/strawberry/perl/bin/perl.exe
  2.  
  3. use strict;
  4. use warnings;
  5. use DBI;
  6. use CGI qw(:standard);
  7. use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
  8.  
  9. print header();
  10. warningsToBrowser(1);
  11.  
  12. my $dbh = DBI->connect("DBI:mysql:survey", "root", "", { RaiseError => 1 } )
  13.                or die "Couldn't connect to database: " . $DBI::errstr;
  14.  
  15. print start_html(),
  16.       h1("It worked");
  17.  
  18. print end_html();
Dec 6 '09 #4

P: 35
nothing works , i get this from apache log:
Expand|Select|Wrap|Line Numbers
  1. [Sun Dec 06 20:06:56 2009] [error] [client 127.0.0.1] Can't locate DBI.pm in @INC (@INC contains: C:/xampp/perl/strawberry/perl/lib C:/xampp/perl/strawberry/perl/site/lib C:\\strawberry\\perl\\vendor\\lib .) at C:/xampp/cgi-bin/DB.pl line 4.\r
  2. [Sun Dec 06 20:06:56 2009] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at C:/xampp/cgi-bin/DB.pl line 4.\r
so it looks like it cant find DBI library but the library is there, I got perl strawberry.
Dec 6 '09 #5

Expert Mod 100+
P: 589
If DBI is on your system then based on the paths, I'd say that something wasn't installed properly, or you specified alternate directories during one of the installations and now you have a mix-match (conflict) in the directory structure.

Or, you have 2 separate installations of Perl (xampp and strawberry), which based on those paths is very likely.
Dec 6 '09 #6

P: 35
xampp comes with perl/bin/perl.exe, wich i heard in some kind of mini perl.
when you install strawberry you cant choose directory installation it will install by default in C/program files. So i just changed it of directory and place it in xampp/perl
Dec 7 '09 #7

Expert Mod 100+
P: 589
That's the cause of your problem. Install one or the other, not both.

I don't like xampp because it leaves out a lot of standard modules, forcing you to install them yourself.

My only objection to strawberry is the limitation in its choice of installation locations. Last time I checked you had absolutely no control over its install location.

My preference is to use ActivePerl http://www.activestate.com/activeperl/ and install each of the other items (mysql and apache) separately. This give you the most flexibility.

So, my recommendation is to uninstall xampp and strawberry Perl and start over.
Dec 7 '09 #8

numberwhun
Expert Mod 2.5K+
P: 3,503
Personally, I prefer Strawberry Perl over Active State as AS has such a proprietory module installation system and does not allow you to install any cpan module.

I do agree with uninstalling xampp and SP and installing only one of them. Two Perls on one system is never good.

Regards,

Jeff
Dec 7 '09 #9

Expert Mod 100+
P: 589
Personally, I prefer Strawberry Perl over Active State as AS has such a proprietory module installation system and does not allow you to install any cpan module.
Actually, that's not true. The only thing missing from AS in their base install is the MinGW module (which is in AS's repository). MinGW installs the required compiler and configures CPAN.pm. I use AS's ppm utility for most of my installations, but I can and sometimes do install via cpan.

On the flip side, when using Strawberry Perl, you can install the ppm utility via cpan and have the choice of either cpan or ppm.
Dec 7 '09 #10

P: 35
i have never installed this mini perl version that's included with xampp , it is install ed by default and it just consist of a bin directory with inside a perl.exe file so i dont see how this could be affecting anything, btw if i uninstall xampp i would need to install php, apache, mysql, perl, phpmydamin etc .. separately but i 've never done this and looks like overkill right now , any tutorials on this ?
thanks
Dec 7 '09 #11

Expert Mod 100+
P: 589
A simple google search will provide numerous tutorials.

Here's one:
http://www.ricocheting.com/server/
Dec 7 '09 #12

Post your reply

Sign in to post your reply or Sign up for a free account.