I have changed my server to a new one and after copying my files to the new server and setting configuration I have a problem with the connection to MySQL using PHP.
I can still connect to my database using my username and password using Bash command line or MySQL Workbench. I'm stuck with it. Any suggestions?
Server ubuntu 16.04, Http server: Nginx
PHP version: 5.6
MySQL version: 5.7.20
My PHP config file:
define("DB_HOST", "localhost");
define("DB_NAME", "zlproject");
define("DB_USER", "username");
define("DB_PASS", "password");
define("DB_PORT", "3306");
My connection script:
public function connect() {
if (!isset($this->connection)) {
$this->connection = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";dbport=" . DB_PORT . ";charset=utf8", DB_USER, DB_PASS);
}
return $this->connection;
}
Error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)'
UPDATE
I resolve my problem and it will be a lesson for me. My defined password in config file contained $
sign so half of my stored passwords was tried to read like a another variable and it caused error.