Page 1 of 1

Call Script from within script on server

Posted: Thu Oct 31, 2019 6:53 pm
by hrcap
Hi Guys

I hope that everyone is well.

Is it possible to call another script from within a script held on a the hosted server (the same way as you call a script only stack when working in a local environment)


EXAMPLE:
If you have an app that sends a post to a script on the LiveCode server (I'll give a simplified version below)

-local app sends post to server based script

- Server receives request

Code: Select all

put $_POST["INSTRUCTION"] into t_instruction

if t_instruction is "run_second script" then

script_connect_to_db --this should call another script held on the server
put the result into t_id_connection_hosted

revclosedatabase t_id_connection_hosted

end if



-the script_connect_to_db should then be called

Code: Select all

put revOpenDatabase("mysql","test.livecodehosting.com","test_db","test_user","test_password") into t_id_connection_hosted
  
  put t_id_connection_hosted


-it should then pass the connection id t_id_connection_hosted back to the original script

- then the connection should be closed


Many Thanks

HRCAP

Re: Call Script from within script on server

Posted: Thu Oct 31, 2019 8:03 pm
by ghettocottage
Yep. You can make your page a regular webpage unless there is something specific is posted to it. Something like:

Code: Select all

<?lc

        --if this is a db connection request, get it and exit
        put $_POST["INSTRUCTION"] into t_instruction
	if t_instruction  is not empty  then
		 include "connect/dbconnect.lc"
                    
        quit

         else  --if this is something else

      	  include "parts/header.lc"
                include "parts/content.lc"
      	  include "parts/footer.lc"

	   end if

?>
the parts can just have html in it to display some webpage.

the dbconnect script can have all of the connection stuff. The t_instruction will carry over.

You could also secure it a little further with some passwords, usernames, etc.

Re: Call Script from within script on server

Posted: Fri Nov 01, 2019 1:13 am
by hrcap
wonderful thank you

I think the part I was missing was the 'include' which seems to be how you get a 'script only stack' to run when calling it from a server based script, i.e.

include "script_connect_to_db"



thanks for your help