mysql_connect won't when run from web server

Steven A. DuChene linux-clusters at mindspring.com
Sun May 24 15:53:17 MST 2009


Hello all:
I have a php to mysql database connection script that I am having a problem with.
I have two systems. One is running apache and also happens to be my desktop system.
Call this one system Apache. The other system is running mysql and let's call this
one Mysql.

the connection script is very simple:

    <?php
    $dbhost = "Mysql";
    $dbuser = "someuser";
    $dbpass = "NOTREAL";

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("Error connecting to mysql");

    if ($conn) {
    echo "CONNECT OK";
    }

    $dbname = "tmp";
    mysql_select_db($dbname);
    ?>


If I run this script from the command line on the Apache system like so:

$ php testmysqlconnect_script.php

and it works fine. However if I run the script from the web browser open on the
Apache desktop and point it at http://localhost/~meuser/testmysqlconnect_script.php
I get a connection error. Just to confirm I have also used the following mysql
command from the command line on the Apache system and it works fine as well:

mysql --host=Mysql -u someuser -p tmp

and entered the exact same user name as is in my script and I am able to connect
just fine. I have tried looking at the output from php_info() on the Apache web
server and it looks normal but I could be missing something.

Anyone have any ideas of what I might be over looking???
--
Steve DuChene




More information about the PLUG-discuss mailing list