0

I am stuck at a point where I need to ask for some assistance as this is my first time working with an external database using PHP. I get the following error when running my PHP script.

mysqli::__construct(): (HY000/1045): Access denied for user 'user'@'localhost' (using password: YES)

The PHP script I am trying to execute:

 shell_exec("ssh -f -L 3307:127.0.0.1:3306 root@mydomain.com sleep 60 >> logfile");
    $mysqli = new mysqli($servername, $username, $password, $dbname);
     $sql = $mysqli->prepare("INSERT INTO users (name, email, password, first_name, last_name, cell_no) VALUES (?, ?, ?, ?, ?, ?)");
     $sql->bind_param("ssssss", $loginUsername, $emailAddress, $sitePass, $firstName, $lastName, "cellNr");
     $sql->execute();

Any assistance would be greatly appreciated.

Pushka
  • 1
  • Does this answer your question? [Warning: mysqli\_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)](https://stackoverflow.com/questions/25174183/warning-mysqli-connect-hy000-1045-access-denied-for-user-usernameloca) – Mohd Alomar Jan 25 '21 at 07:00

1 Answers1

0

Check your my.cnf or my.ini file to see if you have the "bind-address" parameter set. If it is, comment it out and restart mySQL.

Note that your error is occuring on line 2. Lines 3-5 of your code aren't even getting executed. Either you have the wrong password, wrong username, or your mySQL server isn't allowing remote connections.

Possible duplicate of:

MySQL: How to allow remote connection to mysql

Although I am a bit confused why you are using shell_exec here when you appear to be accessing 127.0.0.1. If your MySQL instance is on the same server as your php interpreter, you definitely don't need that line. Just set $servername to "localhost" or "127.0.0.1".

Matt
  • 31
  • 1
  • 3
  • Thanks using a combination of the bind address parameter + allowing the remote connection in mysql I am now able to connect. – Pushka Jan 25 '21 at 07:08