2
現在我創建一個SSH隧道,這樣我就可以連接到我的遠程數據庫,但由於某些原因的連接仍然拒絕...... 我的腳本:腓 - PDO SSH隧道
try {
$host = 'remote host';
$sshuser = 'ssh user';
$sshpass = 'ssh password';
$dbuser = 'db user';
$dbpass = 'db user';
$dbname = 'db name';
shell_exec("ssh -p$sshpass ssh -o StrictHostKeyChecking=no -f -L 3307:127.0.0.1:3306 [email protected]$host");
$dbh = new PDO('mysql:host=127.0.0.1;port=3307;dbname=' .$dbname. '', $dbuser, $dbpass);
$sth = $dbh->prepare("SELECT * from table");
$sth->execute();
$result = $sth->fetchAll();
print_r ($result);
shell_exec("kill $(ssh-pid)");
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
而且結果我得到:
Error!: SQLSTATE[HY000] [1130] Host 'host' is not allowed to connect to this MySQL server
ssh隧道保持活動狀態嗎?數據庫服務器已經在端口3307本地運行了嗎?那個用戶真正的MySQL服務器連接/授權許可是什麼? – mario
您是否找到解決方案? – PeMa