Problem :
I have recently installed Ubuntu 16.04 and installed web server on it. Everything works well, but I am unable to access database. Even if I create new user and grant all privileges, I can't create database In PHP I am getting below error:
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
When I try to login in the terminal, it works, but in the PHP and phpmyadmin don't.
My PHP Code:
protected $myhost = '127.0.0.1';
protected $mydb = 'dbname';
protected $myname = 'root';
protected $mypass = 'root';
protected $myconn;
private static $mysettings = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
);
public function __construct() {
try {
$this->myconn = new PDO("mysql:myhost=$this->myhost;dbname=$this->mydb", $this->myname, $this->mypass, self::$mysettings);
} catch (PDOException $e) {
echo $e->getMessage();
}
}