PHP 使用 ssh2_exec 使用查询中的参数执行脚本
PHP using ssh2_exec to execute script with parameters from query
我正在尝试从服务器执行脚本,参数是从 MySQL 查询中检索并存储到 $test
有没有办法将其用作我的脚本的参数?我还有一个脚本存储在参数中 $script
<?php
include("db.php");
$user = 'user';
$password = 'pwd';
$script = '/my/path/to/script/script.sh';
...
$testResult = mysqli_query($dbConnection, $queryNextTest);
$test = $testResult->fetch_object()->test_script; //this is my parameter obtained from query
$stream = ssh2_exec($connection, $script); //how can I use test as my paramter to execute the
?>
所以我正在寻找的是这样的东西:$stream = ssh2_exec($connection, '/my/path/to/script/script.sh $test');
但是 $test
不能在引号内。
您应该将引号更改为双引号并使用大括号来表达您的变量,如下所示:
$stream = ssh2_exec($connection, "{$script} {$test}");
或者甚至没有像这样的花括号:
$stream = ssh2_exec($connection, "$script $test");
我正在尝试从服务器执行脚本,参数是从 MySQL 查询中检索并存储到 $test
有没有办法将其用作我的脚本的参数?我还有一个脚本存储在参数中 $script
<?php
include("db.php");
$user = 'user';
$password = 'pwd';
$script = '/my/path/to/script/script.sh';
...
$testResult = mysqli_query($dbConnection, $queryNextTest);
$test = $testResult->fetch_object()->test_script; //this is my parameter obtained from query
$stream = ssh2_exec($connection, $script); //how can I use test as my paramter to execute the
?>
所以我正在寻找的是这样的东西:$stream = ssh2_exec($connection, '/my/path/to/script/script.sh $test');
但是 $test
不能在引号内。
您应该将引号更改为双引号并使用大括号来表达您的变量,如下所示:
$stream = ssh2_exec($connection, "{$script} {$test}");
或者甚至没有像这样的花括号:
$stream = ssh2_exec($connection, "$script $test");