MySQL access denied via PHP only

MySQLPHP

I have access to shared university research server that I want to host a php/mysql site on. I've compiled and run the mysql server and can connect to it fine using the 'mysql -u -h localhost -p', however when I use the exact same credentials and parameters through a PHP script, I always get 'access denied for user@localhost'. I did some more digging and found that even when my instance of the server isn't running, I get the same error message, which suggests there is an issue with the fact that this server is shared and running possibly multiple instances of mysqld. I've tried altering the port and socket and connecting to them explicitly through the script, but still have no had any luck. My PHP code works fine locally, so there's nothing syntactically wrong as far as I can tell.

Has anyone experienced a similar problem or can perhaps point me in the direction of some resources? Thanks in advance for your time!

Best Answer

I've had this before. It turned out to be a problem with localhost not resolving properly or reliably. See what happens if you replace that with 127.0.0.1