I can connect to my database from a comman-line PHP script and from the mysql command line interface. I cannot connect from a PHP script launched through apache.
Windows server 2011.
This (included from the same file that the successful command-line script uses, and with real values in the quotes) doesn't do anything except make the rest of the script not load. No errors or warnings, nothing showing up in any of the windows event logs:
<?php
$db = new mysqli('localhost', 'user', 'password', 'database');
?>
Is there any way to get messages telling what's ailing this thing?
cannot connect to mysqli, no errors
Moderator: General Moderators
Re: cannot connect to mysqli, no errors
If I run a PHP script from the command line PHP apparently has access to the loaded extensions. Because it runs, connects to the database, spews database results all over my screen.
From the web server it appears PHP does not have access to any of its extensions. info.php tells me mysql is in my PATh, _SERVER["PATH"], _ENV["PATH"], but there is no other mention of mysql. Or imap. Yet both work in a script run from a command line.
From the web server it appears PHP does not have access to any of its extensions. info.php tells me mysql is in my PATh, _SERVER["PATH"], _ENV["PATH"], but there is no other mention of mysql. Or imap. Yet both work in a script run from a command line.
Re: cannot connect to mysqli, no errors
There's a different ini path when running through apache than from the command line. A simple fix, if a bit hard to find info on.
Re: cannot connect to mysqli, no errors
You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you by reporting and displaying all the errors it detects, you can also enable it in the script adding this 2 lines at the beginning of your code (after the opening <?php of course)
also .. what phpinfo() shows?... run this code
and in the result look for which php.ini is being used ... scroll down and look in the CORE section which extension_dir is used and check that you have there the mysqli extension... and also scroll a little more and look if the mysqli extension has been loaded.
Code: Select all
error_reporting(E_ALL);
ini_set("display_errors", 1);Code: Select all
<?php
phpinfo();
?>Re: cannot connect to mysqli, no errors
Well, the problem was it wasn't finding the php.ini file
The CLI script was running because launching it that way used the php.ini file I had prepared, while in apache it did not. I fixed that by setting the ini path in apache.
THanks.
THanks.