#!/usr/bin/perl # Loader.pl stripped down to MySQL connect error (15mar01) use strict; use CGI qw/:standard *table start_ul/; # load standard CGI routines use CGI::Pretty; use DBI; use CGI::Carp qw /fatalsToBrowser/; my %INI; my $dbh = undef; print "Content-Type:text/html\r\n\r\n"; print "\n"; print "\n"; print "MySQL connect failure test\n"; print "\n"; print "\n"; $INI{DBname} = 'Loader'; $INI{DBuser} = 'apache'; $INI{DBpass} = ''; print "opening database |$INI{DBname}|$INI{DBuser}|$INI{DBpass}|\n"; if ( $dbh = DBI->connect("DBI:mysql:$INI{DBname}",$INI{DBuser},$INI{DBpass}) ) { my $stmt = 'SELECT * FROM ipstat ORDER BY sortip'; if ( my $sth = $dbh->prepare($stmt) ) { if ( my $rows = $sth->execute ) { print "\n"; while ( my $dat = $sth->fetchrow_hashref ) { # output the line print ""; print ""; print "\n"; } # while print "
$dat->{ip}
\n"; } else { ERRreport("ERROR: Could not fetch rows from |$stmt| $@",1); } } else { ERRreport("ERROR: Could not prepare statement |$stmt| $@",1); } $dbh->disconnect(); } else { ERRreport("ERROR: Could not connect to |$INI{DBname}| as |$INI{DBuser}|$INI{DBpass}| err|$@|",1); } print "\n"; print "\n"; ################################## sub ERRreport { my $errmsg = $_[0]; my $severity = $_[1]; print PAGE "$errmsg
\n"; if ( $severity ) { print "$errmsg
\n"; } else { print "$errmsg
\n"; } } #Running the above code from the command line produces the following output # # # MySQL connect failure test # # # opening database |Loader|apache|| # # # # # # Same code called from a form gives the folowing result # # # MySQL connect failure test # # # opening database |Loader|apache|| # ERROR: Could not connect to |Loader| as |apache|| err||
# # #### # host = % Db= test User=(none) select=Y ... # host = % Db= Loader User=apache select=Y ... # host = localhost Db= Loader User=apache select=Y ... # host = 127.0.0.1 Db= Loader User=apache select=Y ...
127.0.0.1
128.0.0.1