1
I’m trying to create a BD via PHP script, but is returning ACCESS DENIED.
<?php
$dbhost = 'localhost';
$dbuser = 'usuario_root';
$dbpass = 'senha_root';
$conn = new mysqli($dbhost, $dbuser, $dbpass);
if($conn->connect_error )
{
die('Could not connect: %s' . $conn->connect_error);
}
echo "Connected successfully\n\n";
$sql = "CREATE DATABASE novobd";
if($conn->query($sql)===TRUE){
echo "Created the database\n";
}
else {
echo "Failed to create the database: ".$conn->error;
}
//Close the database
$conn->close();
?>
ERROR:
Connected successfully Failed to create the database: Access denied for user 'usuario_root'@'localhost' to database 'novobd'
It would be some configuration in Cpanel, or in PHP.ini?
I edited the question with the error. The user is root.
– Guilherme Lirio
But you were able to connect?
– Fabio William Conceição
Yes, connect can. I just can’t create the comic.
– Guilherme Lirio
So in your case it is permissions problem, try to contact the DBA or responsible of your host and check if the user you are trying to connect has permissions to connect to the database.
– Fabio William Conceição
The user term access yes, is the root user, which access Cpanel, etc. =/
– Guilherme Lirio