Newbie Question - Calling multiple .sql scripts to PHP file
I have a PHP file that executes multiple sql scripts. I find that the first two scripts are executed, but the last two never complete. I've tested the last two scripts separately in my PHP files and scripts, so I'm wondering if it has something to do with the number of exec () calls I'm making in my PHP script. Any suggestions? Here's the original script:
<?php
session_start();
$host = "localhost";
$user = "user";
$pass = "pass";
$database = "database";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = sprintf("SELECT dbName FROM users where userName='%s'",
$_SESSION['MM_Username']);
$resultID = mysql_query($query) or die("Data not found.");
list($dbName)= mysql_fetch_row($resultID);
exec("mysql -u user -ppassword ".$dbName." < ../scripts/makeTblFinalAnalysis.sql");
exec("mysql -u user -ppassword ".$dbName." < ../scripts/tblFinalDetailed.sql");
exec("mysql -u user -ppassword ".$dbName." < ../scripts/TblGridViews.sql");
exec("mysql -u user -ppassword ".$dbName." < ../scripts/makeTblGeo.sql");
header( 'Location: dashboards/dashboard.html' ) ;
exit;
?>
"but the last two will never complete." perhaps due to some blockages on the first two scripts, the third script is deadlocked? you can try to execute these scripts on all four of them in your sql server to check if it succeeds and what changes are made. It may also require publishing sql queries.
a source to share
Try to join all execs in a shell script and run it. Then try running it in the background. But then PHP won't wait for the script to return.
exec("nohup sqlRoutines.sh > /dev/null 2>&1 &");
this will detach the script from the calling process and redirect stdout and stderr to nowhere (or to a log file if you want ...).
a source to share