0

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.

1
  • Would be good if you could post your solution for this, if you got it solved. Commented Mar 3, 2014 at 0:49

1 Answer 1

1

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..

Sign up to request clarification or add additional context in comments.

2 Comments

@user2936213 how about you dump it. and lets have a look? what CI version are you using?
I am using Codeigniter 1.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.