I have a php script that connects to a database and does inserts/updates, obviously, if I run the script using the browser, it executes successfully, moving it into production this won’t happen.
I would like to ask how can I invoke the php.exe using a batch script that then runs the php script I have created to do the inserts/updates.
I have the ff: setup
I’m using xampp, with the ff:
webdirectory/cronjobs/cronjob.php -> does the inserts and updates
webdirectory/cronjobs/runscript.bat ->will run the cronjob.php
runscript.bat
@echo off
php.exe -f ../webdirectory/cronjobs/cronjob.php
cronjob.php
include_once('../db/dbcon.php');
$test = $db->run();
.... insert/update codes
Additionally, when I try to run the batch script directly using command line for Win7, using drive:>/xampp/php/php.exe -f drive:>xampp/htdocs/webdirectory/cronjobs/cronjob.php
I get the ff: error;
Warning: include_once(): Failed opening '../webdirectory/db/dbcon.php' for inclusion (include_path='.; E:\xampp\php\PEAR') in E:\xammp\htdocs\webdirectory\db\dbcon.php on line xx
I guess the relative file path is failing; Follow-up question tho, does that mean I have to edit my script file and set the path to absolute? Instead of using ../webdirectory/db/dbcon.php , I should use e:/xampp/htdocs/webdirectory/db/dbcon.php ? Looks like a bad thing to me…
Can somebody please help?
change the directory to the location of the script to make all relative paths work when beeing executed from outside the script’s directory
cronjob.php