简体   繁体   中英

Can't run shell_exec(.php) with mysql in php script

Different from the other situations I found here on SO

I have the following code in the main php script

include("sql.php"); //holds all the data to mysql (and variable $db to connect)

$output = shell_exec('/usr/local/bin/php folder/another_script.php')

and in another_script.php I have this:

include_once("../sql.php"); //notice difference to previous include in the other script

$query = "some query";
$db->query($query)

$output in the first script is blank. The second script runs when alone and not called from another script. What am I missing?

The documentation says:

Execute command via shell and return the complete output as a string

It returns the output. You never use the output, hence nothing is shown. You could do this:

$output = shell_exec('/usr/local/bin/php folder/another_script.php')
echo $output;

Yet, I advise you to reconsider your design to create classes or functions to separate functionality instead of calling (quite expensive) shells to call PHP code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM