Reputation: 53241
I'm trying to connect to MySQL from PHP (WordPress) on Windows / IIS 7.5 and this is what happens:
define('DB_HOST', 'DevPC'); // -> works
define('DB_HOST', 'localhost'); // -> connection error
Strange is that on another machine (Windows Server + IIS 7.5), localhost
works just fine. What can be causing this? Some PHP settings? MySQL settings?
Upvotes: 1
Views: 781
Reputation: 1477
You should give us the error output from the connection. Are you sure it's not a user access problem? Remember that user@DevPC
is not the same as user@localhost
when connecting to mysql. Even if both hostnames translates to the same IP.
Upvotes: 2
Reputation: 1224
In windows you can check
c:\windows\system32\drivers\etc\hosts
to know if the line
127.0.0.1
localhost is there.
/etc/resolv.conf in linux
Upvotes: 0
Reputation: 197757
On Unix, MySQL programs treat the host name
localhost
specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a--port
or-P
option is given to specify a port number.
Instead of localhost
use 127.0.0.1
.
Upvotes: 3