I have a PHP script file that loads a series of CSV files into a MYSQL database.
when I run the script from the command line all going well but when I run it from a browser it quits in the middle (after around 65000 records) and 4 files.
<?
if (isset($argv))
{
$_GET['load_date'] = $argv[1];
}
LoadFile('file1.csv');
LoadFile('file2.csv');
LoadFile('file3.csv');
LoadFile('file4.csv');
LoadFile('file5.csv');
LoadFile('file6.csv');
LoadFile('file7.csv');
function LoadFile($File_Name)
{
//global $serverinfo, $username, $password, $database, $dir_path, $dir_env;
include("datacon.inc.php");
mysql_connect($serverinfo, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
//check if the file is existed
if (file_exists($File_Name) == FALSE) {
ECHO "<FONT COLOR=\"red\"> <b> " . $File_Name . " wasn't found </b> </FONT> <br>";
return;
} else {
ECHO $File_Name . " was found, start loading...<br>";
}
//Import uploaded file to Database
$file_handle = fopen($File_Name, "r");
while (($line_of_data = fgetcsv($file_handle, 0, ",", "\"", "\r\n")) !== FALSE) {
$line_import_query = "INSERT STATEMENT...";
//echo $line_import_query . "<BR><br>";
mysql_query($line_import_query) or die(mysql_error());
}
$Count_records_query =
"SELECT COUNT(*) AS COUNTS FROM `" . $database . "`.`TBL_TABLE`";
$Count_records_query_result = mysql_query($Count_records_query);
$Count_records = mysql_result($Count_records_query_result, 0, "COUNTS");
if ($Count_records <= 0) {
mysql_close();
echo "No records were loaded on " . $File_Name . ", somthing is wrong, check the file location/structure <br>";
} else {
echo "<FONT COLOR=\"red\"> <b> " . $File_Name . " were inserted </b> </FONT> <br>";
# Disconnect from the database.
}
fclose($File_Name, "r");
// close the connection
mysql_close();
return;
}
echo "Disconnected from database successfully! <br><br>
<input type=\"Button\" value=\"Ok, Finished! Back\" onclick=\"history.back()\">";
?>
What's wrong? How can I debug this?