I'm calling a php script with shell_exec that runs fully operational WHEN called from the terminal (php somescript.php
). However, using shell_exec I am able to check the "echo test" I'm issuing inside the script but the database queries with $mysqli are not being commited. Here is the script (again, works well when called from terminal):
//CALLED PHP SCRIPT
include_once("../mysqlconnection.php");
$query = "some query";
echo "this gets printed via shell_exec"
$mysqli->query($query); //this does not execute...
and mysqlconnection.php
:
//connects well
$mysqli = new mysqli($db_ip, $db_user, $db_password, $db_database);
What exactly could be the problem? I call the script with shell_exec('php some_script.php');
. Thank you very much for your help.
EDIT:
As I said, everything works well via terminal. A couple of things:
- I have a debug function that is NOT being called although it is in mysqlconnection.php. Worst of it, if I completely mess up the code trying to provoke variable erros (like removing the include) it still "runs". Does nothing.
- If I echo in the original php script it gets printed (as in the first code example
echo "this gets printed via shell_exec"
EVEN if the rest of the code is messed, semicolons missing and etc. I don't really know what might be off, it's odd. It only points all the flaws if ran by terminal although it also echoes the message if called from a php script
root
/folder/called php script
/script that calls the other php script
/mysqlconnection.php
My code is basically exactly how it is here, no need to change anything...