-1

I am currently trying to create a new database in my Wordpress MySQl database to store information. I am running into issues connecting with the database and extracting the data to be displayed on a page. I imported some data into the database through phpMyAdmin. My php to connect to the Wordpress database was:

$servername = "servername";
$username = "username";
$password = "password";
$dbname = "dbname";
  $conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
  die("Connection failed: ".$conn->connect_error);
}
echo "Connected successfully";

For the appropriate username and password I went into my wp-config.php file. I was having ussues finding the servername for the connection. When I used the Server Hostname found in my cPannel it would print connected successfully on my localhost server but I wasn't able to extract the data.

Thanks for the help!

Dharman
  • 30,962
  • 25
  • 85
  • 135
Jvroth18
  • 13
  • 1

1 Answers1

0

You will get this error when the user username does not have the right access to your MySQL database. To resolve the error, you should grant permissions to the user with the following command in MySQL command-line client or phpMyAdmin:

GRANT all privileges ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'password';

but it's not recommended to give a non-root user all privileges, you can create new user and grants custom privileges like this:

GRANT INSERT, SELECT, UPDATE ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'password';
MaryNfs
  • 301
  • 3
  • 12