We help IT Professionals succeed at work.

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?

Last Modified: 2012-06-27
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 '' (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 '' (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 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('', '<user>', '<pass>', '<db name>');
if(mysqli_connect_errno()) throw new Exception('Connection Failed: '.mysqli_connect_error());

Open in new window

Watch Question

Software Developer
Top Expert 2006
This one is on us!
(Get your first solution completely free - no credit card required)
Forced accept.

EE Admin
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.