【发布时间】:2015-02-16 08:24:28
【问题描述】:
我正在使用 ssh2 在远程服务器上进行 mysql 查询。 这是我的台词:
$connection = ssh2_connect("ip_address", 22);
if (ssh2_auth_pubkey_file($connection, "user", ".ssh/id_rsa.pub", ".ssh/id_rsa"))
{
echo("Ok");
}
else
{
die("KO");
}
$stream = ssh2_exec($connection, "mysql -u root --password=password -D db -e 'SELECT * FROM table'");
echo $stream;
当我启动我的命令时,我收到消息“OK”并且 $stream 变量写道:“Ressource id #5” 我不知道为什么它不起作用。我用正确的 ssh 命令在 bash 中测试了该命令:
ssh user@ip_address "command"
它奏效了。 我在等你的帮助 谢谢, 亲切,
【问题讨论】:
-
RTFM: ssh_exec() 返回一个流。然后,您需要从该流 (stream_get_contents()) 中读取以查看远程命令的输出。
标签: php mysql bash ssh libssh2