I'm trying to create a database from php but I can not.
The server I use is a must 8 with plesk
and this is the code with which I am trying:
<?php
$servername = "localhost";
$username = "DB_Admin";
$password = "$4Fd3rnke";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Create database
$sql = "CREATE DATABASE myDB";
if (mysqli_query($conn, $sql)) {
echo "Base de datos creada correctamente";
} else {
echo "Error creando la base de datos: " . mysqli_error($conn);
}
mysqli_close($conn);
?>
The error you are giving me is this:
Error creando la base de datos: Access denied for user 'DB_Admin'@'localhost' to database 'myDB'
I do not know if I have the fault in the user or it could be something else. The user created it with privileges to create databases.
What can I have wrong?
The user in plesk has it this way:
In the last attempt to give privileges to the user I have put this:
$sql = "CREATE DATABASE myDB GRANT ALL PRIVILEGES ON myDB.* To 'DB_Admin'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;";
But at the moment I get syntax error.