PDO Host Disregarded
I am setting up Symfony2 and, as part of the process, using the PDO extension for the first time. I got it setup alright, but I am having a problem specifying my hostname in the DSN. The MySQL host is on a different server and I am including that in the DSN (say "beta.example.com"). Yet the error message returned always says that there was an access denied response at the local server (say "alpha.example.com").
Just note: there is a MySQL server running local (on "alpha.example.com"), hence the access denied message, but the one I need to use is running on beta.example.com.
My DSN:
mysql:host=beta.example.com;port=3306;dbname=testdb;charset=UTF8
Here is a screenshot of the exact error attached (with hostnames modified to match my ex开发者_开发技巧amples above):
https://skitch.com/nathanntg/gbrhx/pdo-exception
And it is not related to Symfony, it happens if I directly call the PDO creation from a blank PHP file:
<?
$a = new PDO('mysql:host=beta.example.com;port=3306;dbname=testdb;charset=UTF8', 'testuser', 'password');
?>
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'testuser'@'alpha.example.com' (using password: YES)' in -:2
Stack trace:
#0 -(2): PDO->__construct('mysql:host=beta…', 'testuser', 'password')
#1 {main}
thrown in - on line 2
Any help is greatly appreciated!
The "Access denied" message is generated by the contacted MySQL server and does not (necessarily) reflect the DNS name you're using.
Make sure that beta.example.com
resolves to the host you're using (with host beta.example.com
). Also, the configuration on that MySQL server might be somehow messed up. If you log in to beta.example.com from beta.example.com, do you get the same error message?
You can find out what host is contacted by creating a packet trace (for example with wireshark). A simple alternative is temporarily stopping (or firewalling) the MySQL server on beta.example.com and seeing whether the error message changes.
精彩评论