【问题标题】:"Ressource id #5" returned when using mysql in ssh2_exec在 ssh2_exec 中使用 mysql 时返回“Ressource id #5”
【发布时间】: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"

它奏效了。 我在等你的帮助 谢谢, 亲切,

【问题讨论】:

标签: php mysql bash ssh libssh2


【解决方案1】:

我认为phpseclib, a pure PHP SSH implementation 可能会让你更幸运。例如。

<?php
include('Net/SSH2.php');
include('Crypt/RSA.php');

$ssh = new Net_SSH2("ip_address", 22);
$key = new Crypt_RSA();
$key->loadKey(file_get_contents(".ssh/id_rsa"));
if ($ssh->login('user', $key)) {
    echo "Ok";
} else {
    die("KO");
}
echo $ssh->exec("mysql -u root --password=password -D db -e 'SELECT * FROM table'");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 2014-12-05
    • 2020-10-19
    • 2011-09-22
    • 2015-12-28
    • 2015-07-02
    • 2015-10-22
    相关资源
    最近更新 更多