Link to home
Start Free TrialLog in
Avatar of jgruhltuneup
jgruhltuneup

asked on

Why would mysqli connect (to remote server) work on the php command line and not through apache when both CLI and apache php are using the same php.ini file?

When I run the attached code snippet from the command line (php mysqltest.php) the code works and a connection to the remote DB is successful. When I run this same code snippet via apache I get the following error:

Warning: mysqli::mysqli() [function.mysqli-mysqli]: (HY000/2003): Can't connect to MySQL server on '192.168.3.100' (13) in /var/www/tuneup_server/ts_00_02_00/html/index.php on line 5

Fatal error: Uncaught exception 'Exception' with message 'Connection Failed: Can't connect to MySQL server on '192.168.3.100' (13)' in /var/www/tuneup_server/ts_00_02_00/html/index.php:6 Stack trace: #0 {main} thrown in /var/www/tuneup_server/ts_00_02_00/html/index.php on line 6

The server this code is running on is at 192.168.3.102. What is the difference? Is it the fact that these processes are run with different users?

PHP: 5.2.5
MySQL:  5.0.22
OS: Redhat Enterprise Linux 5
$connection = new mysqli('192.168.3.100', '<user>', '<pass>', '<db name>');
if(mysqli_connect_errno()) throw new Exception('Connection Failed: '.mysqli_connect_error());

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Robin Hickmott
Robin Hickmott

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin