I’m trying to establish a PHP (5.2.6)/MySQL connection via mysqli.
error_log( sprintf( 'Querying %s:%s (%s) as %s/%s', DBHOST, DBPORT, DBNAME, DBUSER, DBPASSWORD ) );
$mysqli = @new mysqli( DBHOST, DBUSER, DBPASSWORD, DBNAME, DBPORT );
if( !$mysqli ) {
error_log( 'Unable to establish a connection to ' . DBHOST . '.' . DBNAME . ': ' . mysqli_connect_error() );
exit( 'Unable to connect to the db.' );
}
else {
error_log( '--> mysqli connection established' );
}
... more stuff ...
The result of this code is that the initial write to error_log happens (which validates that the constants are defined properly), but nothing else. Nothing. Everything just stops as far as I can tell. No unable to connect message, no connection established message. Just nothing. I can connect to MySQL directly using the parameters defined by the constants (copied and pasted from the log print).
I’ve read about the bug in versions of PHP prior to 5.2.9 and I’ve tried various ways of detecting an error, but there are no changes. Everything just stops and I’m starting to lose my mind trying to figure out what else I can do.
Has anyone ever seen this? MySQLi does seem to be installed–validated by its presence in the output of phpinfo() and by a test for function_exists( mysqli_connect ). Am I missing something obvious because I’m too focused on the details?
Any thoughts would be appreciated.
UPDATE
When I said, “I’ve tried various ways of detecting an error”, I should have been more clear. No other variant included silencing output with the “@”. Please don’t focus on that. That was only included in my last attempt based on something read in the PHP docs.
So first, an apology. I’m working in an unfamiliar environment and didn’t know that error logging was turned off. I turned that on via
ini_set( 'log_errors', true )and started getting the information that I need. I leave this just in case anyone else has a need to search the same problem.