Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
82 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...