0

I'd like to insert this array data to db using insert_batch() of codeigniter

$data = Array ( 
   [0] => Array 
   ( 
      [e_purpose] => blank purpose data on row 2 
      [e_phase] => blank phase data on row 2 
      [e_carmaker] => please input a valid and related carmaker on row 2
      [e_carline] => blank carline data on row 2
      [table] => Expense Budget
      [row] => 2
      [section] => FINANCE 
   )
   [1] => Array 
   ( 
      [e_purpose] => blank purpose data on row 3 
      [e_phase] => please input a valid and related phase on row 3 
      [table] => Expense Budget 
      [row] => 3 
      [section] => FINANCE 
   )
)

and here's my insert query :

$this->db->insert_batch('t_error', $data);

and i've got this error :

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: database/DB_query_builder.php

Line Number: 1542

Backtrace:

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\application\models\Excel_model.php
Line: 21
Function: insert_batch

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\application\controllers\Excel.php
Line: 125
Function: insertError

File: D:\ONNE\OTHERS\_CODING_PROGRAMMING\XAMPP\htdocs\bulus-ci\index.php
Line: 315
Function: require_once

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Array' at line 1

INSERT INTO `t_error` () VALUES ('blank carline data on row 2','please input a valid and related carmaker on row 2','blank phase data on row 2','blank purpose data on row 2',2,'FINANCE','Expense Budget'), Array

Filename: D:/ONNE/OTHERS/_CODING_PROGRAMMING/XAMPP/htdocs/bulus-ci/system/database/DB_driver.php

Line Number: 691

How can i fixed this, Note : i don't want to use loop/iteration

1 Answer 1

2

Though I have not tested it on my computer. But I guess, the problem is with column names. You have to send set same key in all arrays.

$data = array ( 
   array ( 
      'e_purpose' => 'blank purpose data on row 2', 
      'e_phase' => 'blank phase data on row 2', 
      'e_carmaker' => 'please input a valid and related carmaker on row 2',
      'e_carline' => 'blank carline data on row 2',
      'table' => 'Expense Budget',
      'row' => 2,
      'section' => 'FINANCE' 
   ),
   array ( 
      'e_purpose' => 'blank purpose data on row 3',
      'e_phase' => 'please input a valid and related phase on row 3',
      'e_carmaker' => '', //Send blank values'
      'e_carline' => '', //Send blank values'
      'table' => 'Expense Budget',
      'row' => 3,
      'section' => 'FINANCE',
   )
)

Let me know if works for you so that I also can learn the solutions.

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

Comments

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.