Reputation: 1011
I am using codeigniter's **$this->db->insert_batch('mytable', $data); ** but it is giving me error as :
A PHP Error was encountered
Severity: Warning
Message: array_keys() expects parameter 1 to be array, string given
Filename: database/DB_active_rec.php
Line Number: 1113
my controller code is (just a part of it):
foreach ($arrAllergy as $allergy) {
$allergyData[] = array(
"user_id" => $userid,
"allergy_name" => $allergy
);
}
$this->register_model->addAllergy($allergyData);
model:
public function addAllergy($decoded_data) {
$this->db->insert_batch('allergies', $decoded_data);
}
I have searched a lot for this error but didn't found any solution. Any help would be highly appreciated.
Upvotes: 0
Views: 2292
Reputation: 4527
insert_batch
requires
key => value pairs where the
key is the column name of the database
and the value is the value
your array
must be formatted like
Array
(
[0] => Array
(
[column1] => value
[column2] => value
[column3] => value
)
[1] => Array
(
[column1] => value
[column2] => value
[column3] => value
)
)
print_r
your array ,what it looks like..
Upvotes: 1