Thanks for your answers. here's the code and the results (I put them in as comments in the code):

#!/usr/bin/perl # Loader.pl stripped down to MySQL connect error (15mar01) use strict; use CGI qw/:standard *table start_ul/; # load standard CGI r +outines 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 "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>MySQL connect failure test</TITLE>\n"; print "</HEAD>\n"; print "<BODY BGCOLOR=\"white\">\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{DB +pass}) ) { my $stmt = 'SELECT * FROM ipstat ORDER BY sortip'; if ( my $sth = $dbh->prepare($stmt) ) { if ( my $rows = $sth->execute ) { print "<TABLE>\n"; while ( my $dat = $sth->fetchrow_hashref ) { # output the line print "<TR>"; print "<TD>$dat->{ip}</TD>"; print "</TR>\n"; } # while print "</TABLE>\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{DBus +er}|$INI{DBpass}| err|$@|",1); } print "</BODY>\n"; print "</HTML>\n"; ################################## sub ERRreport { my $errmsg = $_[0]; my $severity = $_[1]; print PAGE "$errmsg<BR>\n"; if ( $severity ) { print "<B>$errmsg</B><BR>\n"; } else { print "$errmsg<BR>\n"; } } #Running the above code from the command line produces the following o +utput # <HTML> # <HEAD> # <TITLE>MySQL connect failure test</TITLE> # </HEAD> # <BODY BGCOLOR="white"> # opening database |Loader|apache|| # <TABLE> # <TR><TD>127.0.0.1</TD></TR> # <TR><TD>128.0.0.1</TD></TR> # </BODY> # </HTML> # Same code called from a form gives the folowing result # <HTML> # <HEAD> # <TITLE>MySQL connect failure test</TITLE> # </HEAD> # <BODY BGCOLOR="white"> # opening database |Loader|apache|| # <B>ERROR: Could not connect to |Loader| as |apache|| err||</B><BR> # </BODY> # </HTML>
To AgentM 15apr2001 0030:

the Carp yielded no additional info, but thanks! It will be useful in future code
I'll check the error logs next.

To eejack 15apr01 0507:

Thanks! I created the security hole on purpose out of sheer desperation! I'll fix it later.
mysql.db has the following contents (again, bad security born of desperation):

# 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 ...
This should not matter because it does work from the command prompt but not through apache.
Unless the system user (root in the case of command prompt and apache in the case of the browser call) is piggybacking something on the call to MySQL then the database permissions should be irrelevant.
I think the answer should be in something MySQL is doing. It must have some parameter such as "allow bozo (system) users to connnect = N", but I've found no reference to a variable of this type.
It would seem that it is the (system) user "apache", which has low priorities in the system is not allowed to connect even though it exists as a MySQL user.

The info at http://www/mysql.com/doc/P/r/Privilege_system.html is where I got the information in my original request for help. It was Ch 6.9 rather than 6.10 (so my info was older). Reading it gives me the same info. As you can see from both the mysql.user and mysql.db tables, the user apache without password is wide open for database Loader. This is borne out by the fact that the code works from the command prompt.

What would make a connect to a database, that works from the command prompt, fail from the browser? </CODE>


In reply to Re: Perl Script connecting to Mysql works from command prompt, not from Apache by gary kuipers
in thread Perl Script connecting to Mysql works from command prompt, not from Apache by gary kuipers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.