views:

37

answers:

1

Hi,

I'm having trouble making a secondary MySQL connection (to a separate, external DB) in my code. It works fine in PHP 5.2.9 but fails to connect in PHP 5.3.0. I'm aware of (at least some) of the changes needed to make successful MySQL connections in the newer version of PHP, and have succeeded before, so I'm not sure why it isn't working this time.

I already have a db connection open to a local database. This function below is then used to make an additional connection to a separate, remote directory. The included config file simply contains the external database details (host, user, pass and name). I have checked and it is being included correctly.

function connectDP() {
    global $dpConnection;

    include("secondary_db_config.php);
    $dpConnection = mysql_connect($dp_dbHost, $dp_dbUser, $dp_dbPass, true) or DIE("ERROR: Unable to connect to Deployment Platform");
    mysql_select_db($dp_dbName, $dpConnection) or DIE("ERROR 006: Unable to select Deployment Platform Database");
}

I then attempt to make this new connection simply by calling this function externally:

connectDP();

But when loading the page (in 5.3.0), I get the message:

ERROR: Unable to connect to Deployment Platform

I'm using the optional new_link flag boolean as the fourth argument in the mysql_connect() function and it's still not working.

I've been wracking my brain this morning trying to figure out why this connection doesn't work (while I've done something very similar elsewhere to a separate second database that does work). Any help would be appreciated.

Thanks!

Rich

A: 

Since PHP 5.3 it uses its own MySQL driver (mysqlnd) by default, instead of the libmysqlclient. Depending on platform it can't read the defaults from your MySQL's configuration file (eg. /etc/mysql/my.cnf). You need to edit php.ini and specify the defaults for the extension(s) you use (mysql, mysqli, pdo). For example in Debian you need to specify the path to socket (eg. /var/run/mysqld/mysqld.sock) yourself in the INI file. Just go through the INI file and specify missing options and it should work.

reko_t
Hey, thanks for your response. The remote connection I'm making is to a shared hosting environment using cPanel. Is there any hope, given that I don't have access to the main php.ini file and my.cnf files?
Rich