PHP PDO changes remote host to local hostname
Posted
by
Wade Urry
on Stack Overflow
See other posts from Stack Overflow
or by Wade Urry
Published on 2012-10-08T02:51:49Z
Indexed on
2012/10/08
3:37 UTC
Read the original article
Hit count: 121
I'm trying to connect to a remote mysql server using PDO. However, regardless of the hostname or ip address i supply in the dsn, when the script is run it always reverts the address to the hostname of the local server where the webserver is running.
Google suggests this could be something to do with SELinux and apaches ability to connect to remote databases, however i have SELinux disabled.
Distro: Ubuntu 11.04 x64
Apache version: 2.2.17
PHP Version: PHP 5.3.5-1ubuntu7.11 with Suhosin-Patch (cli)
Edit:
Added code as requested. Though i dont believe this is an issue with my coding as it works fine on the local server, but doesnt allow remote connection.
public function db_connect($driver, $dbhost, $dbname, $user, $pass) {
$dsn = $driver . ':host=' . $dbhost . ';dbname=' . $dbname;
try {
$this->DB = new PDO($dsn, $user, $pass);
}
catch (PDOException $err) {
print 'Database Connection Failed: ' . $err->getMessage();
die();
}
}
$remote_db = new DB('mysql', 'remote_server.domain.tld', 'database_name', 'user_name', 'password');
This is the error message i am receiving.
Database Connection Failed: SQLSTATE[28000] [1045] Access denied for user 'user_name'@'local_server.domain.tld' (using password: YES)
© Stack Overflow or respective owner