I am just setting up a new VPS learning to setup my own web server and stuck at this pretty basic step.
PHP 5.3.3
MySQL 5.1.61
CentOS release 6.2 (Final)
I can connect to the server using mysql at the command line or remotely using Navicat without issues. I’ve put the host as ‘%’ for testing as localhost wouldn’t work either. I have tried with “localhost”, IP, etc.
Connect failed: Access denied for user 'stats'@'localhost' (using password: YES)
Users:
+-----------+---------+
| Host | User |
+-----------+---------+
| % | stats |
| 127.0.0.1 | root |
| localhost | root |
+-----------+---------+
My code:
<?php
$mysqli = new mysqli("localhost", "user", "db", "pw");
?>
Error when running the php script directly from the command line (No web server):
PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'stats'@'localhost' (using password: YES) in /xxx/db.php on line 5
Connect failed: Access denied for user 'stats'@'localhost' (using password: YES)
The same is returned when running through apache.
Thanks in advance.
This line:
Should be:
password comes before database name