php - Faster way for this mysql_query -
$handle = fopen("stock.csv", "r"); while (($data = fgetcsv($handle, 1000, ";")) !== false) { $model = mysql_real_escape_string ($data[0]); $quantity = mysql_real_escape_string ($data[7]); mysql_select_db("verradt33_xoho", $link); $quantity = str_replace("ja", "10", $quantity); $quantity = str_replace("nee", "0", $quantity); $result = mysql_query("update dev_product set quantity = $quantity model = '$model'") or die(mysql_error());
even tho code works, takes long time process 7000+ lines in csv. due having replace ja or nee 10 or 0 every single line.
is there way make faster? can't touch csv file, that's hard part of course.
current load time 40 minutes.
your first question should be: is column model
indexed?
secondly, try commenting out database access's , see how long takes .csv processing!
mysql_select_db("verradt33_xoho", $link); $handle = fopen("stock.csv", "r"); while (($data = fgetcsv($handle, 1000, ";")) !== false) { $model = mysql_real_escape_string ($data[0]); $quantity = mysql_real_escape_string ($data[7]); $quantity = str_replace("ja", "10", $quantity); $quantity = str_replace("nee", "0", $quantity); /* $result = mysql_query("update dev_product set quantity = $quantity model = '$model'") or die(mysql_error()); */ }
if finishes in seconds database accesses causing speed issues.
suggestion: seem changing ja
, nee
numerics keep simple
mysql_select_db("verradt33_xoho", $link); $handle = fopen("stock.csv", "r"); while (($data = fgetcsv($handle, 1000, ";")) !== false) { $model = mysql_real_escape_string ($data[0]); $quantity = mysql_real_escape_string ($data[7]); switch ($quantity) { case 'ja' : $quantity = 10; break; case 'nee' : $quantity = 0; break; } $result = mysql_query("update dev_product set quantity = $quantity model = '$model'") or die(mysql_error()); }
but best hope instant speed index model
column.
Comments
Post a Comment