Php - Pdo Ssh Tunnel

孤街浪徒 提交于 2019-12-24 02:59:15

问题


right now i am creating a ssh tunnel, so i can connect to my remote database, but for some reason the connection is still refusing... my script:

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 $sshuser@$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();
}

And as a result i get:

Error!: SQLSTATE[HY000] [1130] Host 'host' is not allowed to connect to this MySQL server

回答1:


-p$sshpass ssh This particular part of the ssh command seems a bit odd to me. There should probably be a space after -p and the ssh shouldn't be there too.

Also, -p option is for port, not password.



来源:https://stackoverflow.com/questions/36977365/php-pdo-ssh-tunnel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!