1

I'm moving from an hosting service to another one and I've a problem on the DB connection with the new hosting provider.

Environment:

  • PHP 5.4.43
  • MySQL 5.6.32
$sqlHost = "localhost";
$sqlUser = "user";
$sqlPassword = "pwd";
$sqlDatabase = "databasename";

$mysqli = new mysqli($sqlHost, $sqlUser, $sqlPassword, $sqlDatabase);
if($mysqli->connect_errno){
  echo "SQL error: " . $mysqli->connect_error;
  exit;
}

SQL error: Access denied for user 'user'@'localhost' (using password: YES)

In the old hosting provider the only difference was the MySQL version 5.5 and I never had a connection problem.

If I change the connection code with:

$conn = mysql_connect(HOST,DB_USER,DB_PASSWORD) OR die("Unable to connect");
mysql_select_db(DB,$conn);

I can correctly connect to the database with the user I created. What could be the problem?

StarsSky
  • 6,721
  • 6
  • 38
  • 63
  • 4
    Are you sure that the new details are the same as the old? If you're moving providers and you forgot to change details that's one thing to look at. Try copy-pasting the new information, also look into the host, some hosting providers make you connect to an external location, as well as the database - could have a prefix or ending to it. – Jack Hales Dec 04 '16 at 10:25
  • Yeah. Jek is right. – Wolverine Dec 04 '16 at 10:44

1 Answers1

0

It could be that you didnt grant pemissions to your user in your database and all provilige

     grant all privileges on databasename.* to
    'user'@'localhost' identified by 'pwd'
echo_Me
  • 37,078
  • 5
  • 58
  • 78