php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29391 cannot connect to MySQL from the web server
Submitted: 2004-07-26 17:40 UTC Modified: 2004-07-28 22:24 UTC
From: chcaron at nrcan dot gc dot ca Assigned:
Status: Closed Package: iPlanet related
PHP Version: 4.3.8 OS: Solaris 2.8
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chcaron at nrcan dot gc dot ca
New email:
PHP Version: OS:

 

 [2004-07-26 17:40 UTC] chcaron at nrcan dot gc dot ca
Description:
------------
PHP has been installed with "with-mysql=/usr/local/mysql".

PHP 4.3.8
Mysql 4.0.15
iPlanet 6.1

It was working well with PHP 4.3.4 before we upgrade.

Once we upgraded PHP to 4.3.8, we got "mysql_connect(): Can't connect to MySQL server..." when trying to open a page from the webserver. The command-line PHP was still working correctly.

We recompiled PHP with "with-mysql" only (built-in MySQL) and it all started working ok.

Reproduce code:
---------------
<html>
<body>
<?php

$hostname = 'hostname';
$user = 'root';
$passwd = 'password';
$database_name = 'mysql';
$error_connection = 'Cannot connect to MySQL';
$error_db = "Invalid database name ($database_name)";

if (!($connection = @ mysql_connect($hostname, $user, $passwd)))
        die("$error_connection");
if (!(mysql_select_db($database_name, $connection)))
        die("$error_db");

$query = "show tables;";
if (!($result = mysql_query ($query, $connection)))
        die("error");
while ($row = @ mysql_fetch_array($result)) {
 echo "$row[0]<br>";
}
?>
</body>
</html>

Expected result:
----------------
The list of tables should print on the screen if ran from the webserver:

columns_priv
db
func
host
tables_priv
user

If ran from the command line:

nrn1# /usr/local/php/bin/php test_PHP_mysql.php
<html>
<body>
columns_priv<br>db<br>func<br>host<br>tables_priv<br>user<br></body>
</html>
nrn1#

Actual result:
--------------
From the webserver:

Cannot connect to MySQL

From the command line:

nrn1# /usr/local/php/bin/php test_PHP_mysql.php
<html>
<body>
columns_priv<br>db<br>func<br>host<br>tables_priv<br>user<br></body>
</html>
nrn1#

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-26 18:40 UTC] georg@php.net
How about to remove the warning suppress in mysql_connect 
to see what failed? 
 [2004-07-26 20:16 UTC] chcaron at nrcan dot gc dot ca
We are on a production server, so I can't go back to a state where PHP is not working, so here's the original output without warnings that I received from a client when he discovered it was not working (from the webserver):

Warning: mysql_connect(): Can't connect to MySQL server on 'servername' (2) in /directory/where/the/script.php on line 10

Please note it did work from the command line (e.g. /usr/local/php/bin/php script.php), so MySQL is correctly configured. Also, it was working from the webserver just before we upgrade PHP from 4.3.4 to 4.3.8.

I'll try to reproduce the bug on a developement server.
 [2004-07-28 22:24 UTC] chcaron at nrcan dot gc dot ca
We just upgraded a server from 4.3.6 (using bundled MySQL) to 4.3.8 (using external MySQL 3.23.53) with iPlanet 4.1 and 6.1 and did not notice any problems. Of course, it's not exactly the same environment that produced the original bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 02:01:30 2024 UTC