Create BD via PHP => Access Denied!

Asked

Viewed 114 times

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?

1 answer

1

You have how to share an error screen print?

Usually this error occurs in situations:

  1. You have used the incorrect database access credentials (host, user and/or password).
  2. Or for some reason only your host would answer you have no permissions to be accessing / using the database.
  3. The user you are trying to connect doesn’t have these quests.
  • 1

    I edited the question with the error. The user is root.

  • But you were able to connect?

  • 1

    Yes, connect can. I just can’t create the comic.

  • 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.

  • The user term access yes, is the root user, which access Cpanel, etc. =/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.