Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

sql - Interacting with an external DB using PHP and SSH

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 [email protected] 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.

question from:https://stackoverflow.com/questions/65879285/interacting-with-an-external-db-using-php-and-ssh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...