I have a seemingly straightforward call using mysqli_connect() that is failing due to host substitution of the name 'localhost'.
Example:
$username = 'foo';
$host = 'localhost';
$passwd = 'secret';
$link = mysqli_connect($host,$username, $passwd)...
Calling mysqli_connect with either 'localhost' or '127.0.0.1' as the host returns something like this:
(HY000/1045): Access denied for user 'foo'@'servername.mydomain.com'
I can connect using the same account with the locally-installed MySQL client just fine, so the user's permissions are valid:
SHOW GRANTS FOR 'foo'@'localhost';
GRANT USAGE ON *.* TO 'foo'@'localhost'
Evidently mysqli_connect is trying to connect using the DNS name of the local machine instead of localhost.
I know I could opt to issue a grant for the user with the host explicitly defined as the machine name, or allow from all hosts, but neither of those options is acceptable in this instance. I need it to get it to work using localhost.
Related: /etc/hosts defines localhost as follows:
127.0.0.1 localhost