Home > Software design >  Why is my localhost turned into a percentage sign
Why is my localhost turned into a percentage sign

Time:01-19

I am trying to connect to a remote database and the credentials are correct but I get an error and I would like to know why 'localhost' is turned into a % sign and why I am unable to connect. If I use the full remote URL of the database the same thing happens.

Here is my php page:

<?php
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'testuser';
$DATABASE_PASS = 'password';
$DATABASE_NAME = 'table';


$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
  die('<div >Failed to connect to MySQL: ' . mysqli_connect_error() . "</div>");
}
if (!$con) {
  echo "<div class='error'>Not connected</div>";
}

The error I get looks like this:

Failed to connect to MySQL: Access denied for user 'testuser'@'%' to database 'table'

Why is localhost or the full remote address turned into %

CodePudding user response:

The nearest user record in MySQL that matched the username you provided was the MySQL user 'testuser'@'%'. It's not that you provided that name, it's that this is the user record in MySQL. And while the password for it was apparently okay, that user has not been granted permissions for the table database.

  • Related