1

I am trying to execute a script from a server, the parameter is retrieved from MySQL query and stored into $test is there a way to use this as a parameter for my script? I have a script stored in a parameter as well $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 

?>

So what I am looking for is something like this: $stream = ssh2_exec($connection, '/my/path/to/script/script.sh $test'); but the $test cannot be inside the quotes.

1 Answer 1

2

You should change the quote to double and use curly bracket to express your variable like this:

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

Or even without curly braces like this:

$stream = ssh2_exec($connection, "$script $test");
Sign up to request clarification or add additional context in comments.

4 Comments

Am I allowed to combine two variables like this? $stream = ssh2_exec($connection, "{$script} {$test}");
Yes, definitely.
One more question, is it always good to use double quotes? What are the advantages from double quotes to single quotes and vice versa?
No, you each one has its pros and cons in certain cases. You can refer this link for more info: stackoverflow.com/questions/3446216/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.