i want to insert data an array, from array format like this with codeigniter frameworks.
Array ( [run_date] => Array ( [0] => 2015-06-15 11:10 [1] => 2015-06-15 11:10 [2] => 2015-06-15 11:10 [3] => 2015-06-15 11:10 ) [msisdn] => Array ( [0] => 8499270093 [1] => 8599387282 [2] => 6281019183 [3] => 8597375112 ) )
i've been trying to use insert_batch command on codeigniter but it's not works at all. such like below.
My Controller
function insertFromConfirmation() {
$datanew = array(
'run_date' => $this->input->post('run_date'),
'msisdn' => $this->input->post('msisdn')
);
print_r($datanew);
$this->modelMsisdn->insertDataArray($datanew);
}
and My Model
public function insertDataArray($datanew) {
$this->db->insert_batch('subscription_renewal', $datanew);
}
Error Shown:
Error Number: 1054 Unknown column '0' in 'field list' INSERT INTO `subscription_renewal` (`0`, `1`, `2`, `3`) VALUES ('2015-06-15 11:10','2015-06-15 11:10','2015-06-15 11:10','2015-06-15 11:10'), ('8499270093','8599387282','6281019183','8597375112')
Filename: C:\xampp\htdocs\msisdn_tools_new\system\database\DB_driver.php Line Number: 330
Table Structure
CREATE TABLEsubscription_renewal(idint(11) NOT NULL AUTO_INCREMENT,msisdnvarchar(32) CHARACTER SET utf8 NOT NULL,servicevarchar(64) CHARACTER SET utf8 NOT NULL,adnvarchar(8) CHARACTER SET utf8 NOT NULL,operatorvarchar(32) CHARACTER SET utf8 NOT NULL,channelvarchar(16) CHARACTER SET utf8 NOT NULL,statustinyint(4) NOT NULL,descriptionvarchar(20) CHARACTER SET utf8 DEFAULT NULL,blacklist_statustinyint(4) NOT NULL,date_createddatetime NOT NULL,date_modifieddatetime NOT NULL,run_datedatetime DEFAULT NULL,pricevarchar(30) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=476 DEFAULT CHARSET=latin1
('0', '1', '2', '3')check database tables field names are correctINSERT INTO subscription_renewal ('id','run_date','msisdn') VALUES ('0','2015-06-15 11:10','8499270093');Do not use insert_batch. you can use insert_string and a 'for each' loop to do this multiple row insertion