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();