-1

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...

Fane
  • 1,978
  • 8
  • 30
  • 58
  • Does `$mysqli->query($query)` give you an error or it doesn't even reach that line? – GiamPy Sep 13 '15 at 16:19
  • 2
    Sorry Fane, pseudo code does not give enough information for anything other than **a guess** Show the real code. Also any errors, from the php error log – RiggsFolly Sep 13 '15 at 16:23
  • Possibly something to do with include. Are you getting any warnings or notices? – CJD Sep 13 '15 at 16:30
  • You dont seem to be interested in providing any useful information so I suggest we close this question, as UNCLEAR WHAT YOU ARE ASKING – RiggsFolly Sep 13 '15 at 16:50
  • @RiggsFolly wait please, I'm sorry I'll update the question and let you know – Fane Sep 13 '15 at 16:53
  • @RiggsFolly Updated, hope it is more detailed – Fane Sep 13 '15 at 18:34
  • @CJD Updated, hope it is more detailed – Fane Sep 13 '15 at 18:35
  • @GiamPy Updated, hope it is more detailed – Fane Sep 13 '15 at 18:35
  • (sorry for the spam) – Fane Sep 13 '15 at 18:35
  • Fane: Not really any more use then you first try. Do you believe that your real code is so special we are all going to steal you ideas? – RiggsFolly Sep 13 '15 at 18:45
  • @RiggsFolly Nope, neither my ideas are special but guess what, I could change this code to my real code and you wouldn't consider thinking about it either because you seem more interested in being non constructive instead of really figuring the problem. Everything is there, so the flaw can be noticed now. Please **DO** consider being helpful here. – Fane Sep 13 '15 at 19:06
  • Fane: How can I possibly help you **by making guesses**, as thats all we can do with the **mimimal information** you are supplying to us. Remember we are not **clairvoyant** and we are **not looking over your shoulder** – RiggsFolly Sep 13 '15 at 19:08
  • Ok lets take the long route! Where are you running the main script from? A web page script? A Cron job? Some other terminal process??? – RiggsFolly Sep 13 '15 at 19:37
  • @RiggsFolly From a regular POST to php with no arguments. Most surely relevant. – Fane Sep 13 '15 at 20:32
  • OK so does the account that your web server runs under have permissions to access the folders that hold this code? I am assuming you are using a unix/linux – RiggsFolly Sep 13 '15 at 20:33
  • @RiggsFolly See, now you are asking the real questions!!! As I said, there is echo output from the script, so I know it is being accessed... I tried messing up the script name in `shell_exec` call (edit: and it did warn "no script with that name", I fixed it back) so I'm assuming it is being called correctly (given also the echo from the script)... – Fane Sep 13 '15 at 20:35
  • No I am having to pull relevant info from you like pulling teeth – RiggsFolly Sep 13 '15 at 20:52
  • Did you change the working directory before calling the shell_exec so that the relative file locations will work porperly. So now I am going to say let us see the actual code where you make the `shell_exec()` call – RiggsFolly Sep 13 '15 at 20:55
  • @RiggsFolly No I did not. How should I? – Fane Sep 13 '15 at 20:56
  • [The manual for cwd](http://php.net/manual/en/function.getcwd.php) – RiggsFolly Sep 13 '15 at 21:00
  • So I should run `chdir()` inside the called script? Please check my server structure is at the bottom of my question text – Fane Sep 13 '15 at 21:02
  • @RiggsFolly it F worked. it F worked. I love you man. I F love you – Fane Sep 13 '15 at 21:16

1 Answers1

-1

What exactly could be the problem?

Lack of error reporting.

Having errors properly reported, you will see what is wrong with your include and mysqli query.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • I see, but my common sense is telling me I might already told you there are NO error reports even if I mess up the code although the echoes are **STILL** output. – Fane Sep 13 '15 at 20:33