My program originally called a mySQL query over http. The result was returned in JSON form:
$query = "SELECT xaxis, yaxis FROM table ";
$result = mysql_query($query);
$rows = array();
$counter=1;
while ($r = mysql_fetch_array($result, MYSQL_NUM))
{
echo json_encode($r[0]), "\n";
echo json_encode($r[1]), "\n";
$counter++;
}
?>
It works ok (granted not the best PHP script in the world), but now I’m doing everything in SSH and I was thinking about doing the SQL query through bash and then I thought, why don’t I just call the PHP script in SSH?
However I’m not sure how to do this, given that the PHP returns an array. If it returned a simple file I could, in theory just do:
spc username@hostname:filename localfilename
How should I return get an array from a script in SSH?
The PHP does not return an array. It returns a JSON-format string: remember, HTTP can only ever give you text.
So there is no difference. Just invoke the PHP script in your terminal and you’ll see the same text.
(Actually, it looks like you have two distinct JSON structures, separated by a newline. You might want to fix that by encoding
$rinstead:)Or something like that.