I am trying to learn how to Bulk insert into the following database every 1000 $i rows.
$i = 0;
$data = array();
$param = '';
$sql = "INSERT INTO `myTable` ( `mycolumn`, `othercolumn` ) VALUES ";
while ( $csvfile = fgetcsv($handle, 0, "\t" ) ) {
$param .= "(?, ?),";
array_push($data, $csvfile[0], $csvfile[1]);
if ((!empty($csvfile[0]) || !empty($csvfile[1])) && ($i % 1000 === 0)) {
$this->db->query($sql.$param . implode(", ", $data));
$param = "";
$data =array();
}
$i++;
}
output:
{"error":{"code":500,"message":"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ?),(?, ' at line 1"
How can I fix this algorithm? I haven't found any example that reassembles this so I am asking you. Thanks in advance.