Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

unable to connect to mysql database

by mdeepthi.89 (Initiate)
on Jun 29, 2011 at 22:16 UTC ( #912054=perlquestion: print w/ replies, xml ) Need Help??
mdeepthi.89 has asked for the wisdom of the Perl Monks concerning the following question:

Hello pls help me out.I've been working on this for the past 6hrs.cant figure out what am i doing wrong
#!/usr/bin/perl use DBI; use strict; use warnings; # Database settings my $database = "website"; my $username = "test"; my $password = 'testtest'; my $table = "apartments"; # Connect to database my $dbh = DBI->connect("dbi:mysql:database=$database;host=localhost;us +er=$username;password=$password") or die "Couldn't connect to databas +e: $DBI::errstr\n"; my $sth = $dbh->prepare("select * from $table')") or die "Couldn't pre +pare statement: $dbh->errstr\n"; $sth->execute() or die "Couldn't execute query 'sql': $DBI::errstr\n";
I'm getting an internal server error 500.I dont understand y i cant connect to the database.please help me

Comment on unable to connect to mysql database
Download Code
Re: unable to connect to mysql database
by wind (Priest) on Jun 29, 2011 at 22:30 UTC

    Please enclose your code in code tags as referenced in How do I post a question effectively?

    There's nothing in your code that looks wrong, but what exactly is the error that is being reported? If this is on a web server, try running the code from a shell prompt instead or just examine the error log.

Re: unable to connect to mysql database
by Anonymous Monk on Jun 30, 2011 at 03:39 UTC
    Anytime a CGI script fails, a 500-internal-error message will be produced. It tells you nothing useful. The server logs may contain more; or, not.
Re: unable to connect to mysql database
by Anonymous Monk on Jun 30, 2011 at 04:15 UTC
Re: unable to connect to mysql database
by wfsp (Abbot) on Jun 30, 2011 at 07:10 UTC
    my $sth = $dbh->prepare("select * from $table')")
    Is that right?

    Adding use CGI::Carp "fatalsToBrowser"; at the top of the script might help you see what is happening.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://912054]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-12-27 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls