Welcome Guest, Not a member yet? Register   Sign In
insert_batch() not working completely
#6

(04-20-2017, 01:37 AM)Martin7483 Wrote: The error is very clear.

One of the values your are inserting is an Array and not a string. It literally says that: "Array to string conversion"

Meaning the structure of the array you are passing to the insert_batch method is incorrect

Hope, You have seen my both array. For information, insert_batch() working fine when array keys are same as showing in below array.

Code:
Array
(

[0] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week1
      [mon] => {"time":"1:00 AM","item":"a","description":"a"}
      [created_at] => 2017-04-11 13:27:30
      [updated_at] => 2017-04-11 13:27:30
  )

[1] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week2
      [mon] => {"time":"1:00 AM","item":"b","description":"b"}
      [created_at] => 2017-04-11 13:27:30
      [updated_at] => 2017-04-11 13:27:30
  )

[2] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week3
      [mon] => {"time":"1:00 AM","item":"c","description":"c"}
      [created_at] => 2017-04-11 13:27:30
      [updated_at] => 2017-04-11 13:27:30
  )

[3] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week4
      [mon] => {"time":"1:00 AM","item":"d","description":"d"}
      [created_at] => 2017-04-11 13:27:30
      [updated_at] => 2017-04-11 13:27:30
  )
)

But insert_batch() is not working for below array because array keys are different, Please see below

Code:
Array
(

[0] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week1
      [mon] => {"time":"1:00 AM","item":"a","description":"a"}
      [created_at] => 2017-04-11 13:17:27
      [updated_at] => 2017-04-11 13:17:27
  )

[1] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week2
      [tue] => {"time":"1:00 AM","item":"b","description":"b"}
      [created_at] => 2017-04-11 13:17:27
      [updated_at] => 2017-04-11 13:17:27
  )

[2] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week3
      [wed] => {"time":"1:00 AM","item":"d","description":"d"}
      [created_at] => 2017-04-11 13:17:27
      [updated_at] => 2017-04-11 13:17:27
  )

[3] => Array
  (
      [trainer_id] => 2
      [plan_id] => 2
      [week] => week4
      [thur] => {"time":"1:00 AM","item":"d","description":"d"}
      [created_at] => 2017-04-11 13:17:27
      [updated_at] => 2017-04-11 13:17:27
  )
)

I think, inset_batch() need to be upgrade for insert the data in different columns. 


insert_batch() works fine when array has same keys not via different array keys. That is reason, so insert_batch() working fine for my 1st array not 2nd array.
Reply


Messages In This Thread
RE: insert_batch() not working completely - by krishnadeveloper - 04-21-2017, 11:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB