1

我正在尝试从服务器执行脚本,从 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不能在引号内。

4

1 回答 1

2

您应该将引号更改为 double 并使用大括号来表达您的变量,如下所示:

$stream = ssh2_exec($connection, "{$script} {$test}");

甚至没有像这样的花括号:

$stream = ssh2_exec($connection, "$script $test");
于 2017-09-16T00:27:45.067 回答