Connect to a mysql database via SSH through PHP

前端 未结 2 910
礼貌的吻别
礼貌的吻别 2020-12-19 16:12

I have already written a php file that connects to the mysql database locally. Now, I want to connect to a remote database via SSH. Currently the connect function for my dat

相关标签:
2条回答
  • 2020-12-19 16:52

    The mysql extension doesn't currently support this. Modifying the extension, itself, might not be that difficult, but at that point, it'd have to be a custom PECL extension, at best. The idea was discussed on the PHP Internals mailing list a while back:

    http://comments.gmane.org/gmane.comp.php.devel/79520

    0 讨论(0)
  • 2020-12-19 17:04

    I think you are out of luck on this one. You can either use the ssh extension in your PHP code, or if you have access to the server, you could try to create a ssh tunnel on the command-line.

    You probably need special permissions to do that, though. It also looks like you don't have ssh access to this hosting account.

    duplicate answered by @jpm

    Setting up tunneling posted by @Ólafur Waage on Connect to a MySQL server over SSH in PHP

    And this one for tunneling by @Sosy

    shell_exec(“ssh -f -L 3307:127.0.0.1:3306 user@remote.rjmetrics.com sleep 60 >> logfile”);  
    $db = mysqli_connect(’127.0.0.1′, ‘sqluser’, ‘sqlpassword’, ‘rjmadmin’, 3307);
    
    0 讨论(0)
提交回复
热议问题