I have a table (parts) that has 2 columns in it, 1000 or so rows. The 1st (parts) column has info stored in each row of it. I am updating the 2nd column via a csv files that I am parsing with PHP. That csv file has 2 columns and about half as many rows. The first column in the updating csv file will need to match the row in the first column of the parts table. Then the 2nd column in the csv file will update the 2nd column in the (parts) table.
Im using this query to loop the info into the parts table:
<?php
$file = fopen("csv-file-w-2-columns.csv","r");
require "../db_connect.php";
mysql_select_db("parts", $con);
while(!feof($file)) {
$line = fgets($file);
$values = explode(",",$line);
mysql_query("UPDATE parts SET parts_column2='".$values[1]."' WHERE parts_column1='".$values[0]."'");
}
mysql_close($con);
fclose($file);
?>
In doing this is takes to long, and my script never finishes. If I do this in small bits at a time it works.
Could anyone help with some advice to speed this up, and any info to why it might be stalling like it has been when I process the whole thing at once?
Take a look at your max_execution_time. You can override this INI setting with
set_time_limit. I am guessing that your script is timing out.As for the structure of your code, there isn’t really anything wrong, per se. It’s just taking too long according to the server’s
max_execution_timesetting.