I've modified a PHP script to import a .csv into a table in my database. The only problem with it is that the .csv file contains ~54,000 lines, and only ~14,000 records are being inserted into my table. This is the section of code in question:
$fieldseparator = ",";
$lineseparator = "
";
$dbconn = @mysql_connect($dbhost,$dbusername,$dbpassword) or die('could not connect ' .mysql_error());
@mysql_select_db($dbname) or die('could not connect ' .mysql_error());
$lines = 1;
$queries = "";
$linearray = array();
foreach(explode($lineseparator,$csvcontent) as $line) {
$lines++;
$line = trim($line," \t");
$line = str_replace("","",$line);
// escape ' character
$line = str_replace("'","\'",$line);
/*************************************/
$linearray = explode($fieldseparator,$line);
$linemysql = implode("','",$linearray);
$query = "replace into $dbtable values('$linemysql');";
// I added this line to try and track entries - when run, $lines goes up to my ~54,000
echo "Record number $lines inserted
";
$queries .= $query . "
";
@mysql_query($query);
}
@mysql_close($dbconn);
Can anyone see why only ~14,000 records would be inserted? I'm baffled here.
File is to big and probably there is problem with timeout.
Try to insert directly form PHPmyAdmin, but I think thet you will get same problem.
Maybe to try to made a couple of files from your csv file and them insert them separately.
Good luck! :)