Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have been working on this for 4 days straight. I'm trying to get MySQL data. I've done it before in PHP but never in Perl. I can "show tables" (so I can access the DB) but nothing else works. Even using use CGI::Carp I just always get a blank page.
use DBI; use CGI::Carp qw(fatalsToBrowser); print "Content-type:text/html\n\n"; $db ="my_webapp2"; $user = "my_user"; $pass = "password"; $host="localhost"; $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass); or die "Connecting to MySQL database failed: $DBI::errstr"; $SQLq = ("SELECT username FROM 'sessions' WHERE uid='1'"); $start = $dbh->prepare($SQLq) or die "Preparing MySQL query failed: $DBI::errstr "; $start->execute() or die "The execution of the MySQL query failed: $DBI::errstr"; $result = $start->fetchrow_hashref(); print "Ta-da!: $result->{username}\n"; while ($row = $start->fetchrow_hashref()); $dbh ->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems Getting MySQL Data
by Corion (Patriarch) on Oct 07, 2010 at 07:25 UTC | |
by longjohnsilver (Acolyte) on Oct 07, 2010 at 13:08 UTC | |
by Anonymous Monk on Oct 07, 2010 at 13:32 UTC | |
by Anonymous Monk on Oct 08, 2010 at 00:53 UTC | |
by Anonymous Monk on Oct 08, 2010 at 00:50 UTC | |
by Anonymous Monk on Oct 08, 2010 at 00:47 UTC |