I have csv files what i parse to array and pass to mysql table. Some CSV files does not contains some columns what are in database and when i convert it to array than i have smaller number of columns that are in table and i get "syntax error".
From controller i call:
function sendHistoric(){
$this->load->model('Historic_model');
$this->load->library('csvreader');
foreach($this->divisions as $div){
$result = $this->csvreader->parse_file("assets/csv/1516{$div}.csv");//path to csv file
$this->Historic_model->loadCSVtoDB($result);
//var_dump($result);
}
}
in model i have:
function loadCSVtoDB($data){
$sql = "call ins_historic(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
foreach($data as $row){
var_dump($row);
$this->db->query($sql,$row);
}
//echo $this->db->conn_id->error_message();
}
Can i somehow send NULL instead where he find that i have smaller number of data or i need to check if each element of array exists, if not that set it to null?