1

I am wondering when I instantiate a new PDO object it still uses the local IP of the server.

<?php

$dsn = 'mysql:host=10.0.0.4;charset=utf8';
$username = 'user';
$password = 'pass';

$pdo = new PDO($dsn, $username, $password);

?>

It gives me this weird error.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'user'@'10.0.0.5'
(using password: YES)' in /var/www/html/mysql_test.php:7
Stack trace:
#0 /var/www/html/mysql_test.php(7): PDO->__construct('mysql:host=10.0...', 'user', 'pass')
#1 {main}
thrown in /var/www/html/mysql_test.php on line 7

I noticed that it is connecting to 10.0.0.5 which is the IP address of the local server. The remote server (10.0.0.4) enables remote access.

Is there an internal config file for PDO that I should configure? The current PHP and PDO versions are 5.5.15RC1 and 5.5.38 respectively.

php-dev
  • 6,998
  • 4
  • 24
  • 38
kapitanluffy
  • 1,269
  • 7
  • 26
  • 54
  • it's not connecting to your computer, `user@ip` is the IP of the user connecting, so it should be your computer's IP. the problem is somewhere else. – serakfalcon Jul 21 '14 at 03:42
  • 7
    No, `10.0.0.5` is the `client` IP and not the server IP. The message is stating that the user `user` at the `10.0.0.5` is not permitted to access the server at `10.0.0.4`. – php-dev Jul 21 '14 at 03:42
  • You may be getting this error because you've omitted the `dbname` parameter from your DSN – Phil Jul 21 '14 at 03:54
  • Thanks @php-dev I didn't quite understood the error message. – kapitanluffy Jul 21 '14 at 04:16

0 Answers0