I have some code that I edited for importing csv into mysql using PDO to bind parameters. I thought it was working before, but tested it again and the issue I have is that only one line (the fourth line) of the csv file is getting imported. The first line is the header which are the table field names. The first method below is what's used to parse the csv files and bind the field names with the data. The second method, loops through. I need another pair of eyes, so if anyone can help me figure out my issue, I would greatly appreciated.
public function getSQLinsertsArray($sqlTable)
{
$data = $this->getCSVarray();
$queries = [];
$fieldsStr = "";
while(list($k, $field) = each($data))
{
if(empty($fieldStr)) $fieldStr = implode(", ", array_keys($field));
//$valueStr = "'".implode("', '", $field)."'";
$placeholders = array_map(function($col) { return ":$col"; }, $field);
$bind = array_combine($placeholders,$field);
$queries[] = DB::inst()->query("INSERT INTO ".$sqlTable." (".$fieldStr.") VALUES (".implode(",", $placeholders).");",$bind);
//error_log(var_export($queries,true));
}
return $queries;
}
public function queryInto($sqlTable)
{
$queries = $this->getSQLinsertsArray($sqlTable);
while(list($k, $query) = each($queries))
{
$q = $query;
}
if($q > 0) {
return true;
} else {
return false;
}
}