Phpseclib connect MYSQL server

一笑奈何 提交于 2019-12-24 10:05:58

问题


I want to connect to my remote MySQL server through port forwarding. Unfortunately my hosting provider don't have php_ssh2 installed on the server so I have to work through phpseclib library. So far I am able to do:

1 - Connect to server using Net_SSH2:

$ssh = new Net_SSH2('xx.xxx.xx.xx');  
 if (!$ssh->login('user', 'password')) {  
    exit('Login Failed');  
 }  

If I do echo $ssh->exec('ls -la');, it fetches directory listing telling we are connected successfully.

if I run

2 - echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql');

It triggers:

stdin: is not a tty ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: NO)

3 - If I do echo $ssh->exec('ssh -f -L 3307:localhost:3306 root@xx.xxx.xxx.xxx sleep 60 >> logfile');

It runs forever resulting in no response error from the server.

I am pulling my hair out. HELP!!!!!


回答1:


Maybe try this?:

echo $ssh->exec('echo "select * from table where company_id=\"15\";" | mysql -u username -password=password database');

As is it's probably waiting for a password to be entered.



来源:https://stackoverflow.com/questions/5980409/phpseclib-connect-mysql-server

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