php ssh mysql_通过PHP通过SSH连接到mysql数据库

我已经编写了一个在本地连接到mysql数据库的php文件.现在,我想通过SSH连接到远程数据库.目前我的数据库的连接函数在php中如下:

$this->db = new mysqli(_SERVR_URL, _SERVR_USER , _SERVR_PASS, _SERVR_DB);

if ($this->db->connect_errno) {

echo "Failed to connect to MySQL: (" . $this->db->connect_errno . ") " . $this->db->connect_error;

}

else{

//echo "Successfully connected!!
";

}

我只想更改连接函数(上面),以便其余的代码仍然有效.我已经成功安装了phpseclib并且对安装php的ssh扩展不感兴趣,因为经过近5个小时的努力,这些扩展无法正常工作. phpseclib正在工作,我认为这是因为当我使用require时它不会死.

但是,当我尝试开始使用ssh的东西时,它会抛出一个服务器错误:

$ssh = new Net_SSH1(myURL);

我通常SSH到我的服务器的方式是使用.pem文件.我可以得到一些指导:

>为什么当前代码可能会抛出错误?

>如果可以的话.

>您将如何使用.pem文件编写连接代码.

解决方法:

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.

this one由@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);

标签:php,mysql,mysqli,ssh,phpseclib

来源: https://codeday.me/bug/20190620/1242837.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值