In ubuntu 19.04 with php version 7.2 , i want to add mysql user with php when i run the code below get the error:
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
I didn't set any password for root , this is php code:
<?php
$server = "localhost";
$dbuser = "root";
$dbpassword = "";
try {
$connection = new PDO("mysql:host=$server", $dbuser, $dbpassword);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$user = 'test' . '@' . 'localhost';
$sqlQuery = "CREATE USER . $user . ";
$connection->exec($sqlQuery);
echo "User created successfully!";
}
catch(PDOException $e){
echo $sqlQuery . "<br>" . $e->getMessage();
}
$connection = null;
?>