Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

unable to connect to mysql database

by mdeepthi.89 (Initiate)
on Jun 29, 2011 at 22:16 UTC ( [id://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

Replies are listed 'Best First'.
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.

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 04:15 UTC
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found