Hi guys,
I am using this code:
function importCsv($file, $table) {
$fieldseparator = ",";
$lineseparator = "\n";
$fileOpen = fopen($file, "r");
$fileSzie = filesize($file);
$fileContent = fread($fileOpen,$fileSize);
fclose($fileOpen);
$fileLines = 0;
$fileQuiries = "";
$fileLineArray = array();
foreach(explode($lineseparator,$fileContent) as $fileLine) {
$fileLines++;
$fileLine = trim($fileLine," \t");
$fileLine = str_replace("\r","",$fileLine);
$fileLine = str_replace("'","\'",$fileLine);
$fileLineArray = explode($fieldseparator,$fileLine);
$fileLineMySql = implode("','",$fileLineArray);
$query = "INSERT INTO `$table` VALUES(NULL,'$fileLineMySql')";
$mysqli->query($query);
}
}
My issue is that the field contains a comma (",") and this stuffs up the INSERT.
How can I escape this comma so the code does not think it is a different mysql table column?
Thanks in advance.