簡體   English   中英

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不能在引號內。

您應該將引號更改為double並使用大括號來表示變量,如下所示:

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

甚至沒有這樣的花括號:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM