2016-10-18 2 views
0

기본값이 없습니다 :된답니다 insert_batch 필드 'exp_user은'내 DB에에 "비용"테이블에 행으로 배열을 삽입하려고

public function insert_expense($expenses){ 
    $this->db->insert_batch('expenses', $expenses); 
} 

을하고 나는이 오류가 계속 :

A Database Error Occurred
Error Number: 1364
Field 'exp_user' doesn't have a default value
INSERT INTO expenses () VALUES(),(),(),(),(),(),(),(),(),(),(),()
Filename: models/Expenses_model.php
Line Number: 26

이 내 테이블의 구조입니다 :

enter image description here

그리고 경우 변수 $expenses에서

array(12) { 
    ["exp_user"] "1" 
    ["exp_date"] "2016-10-18" 
    ["exp_date_request"] "2016-10-18" 
    ["exp_client"] "Potato" 
    ["exp_provider"] "Miew" 
    ["exp_amount"] "1" 
    ["exp_currency"] "₪" 
    ["exp_budget"] "budget2" 
    ["exp_method"] "cc" 
    ["exp_frequency"] "Monthly" 
    ["exp_expenditure"] "asdasdas asdas dsa as" 
    ["exp_charge_client"] NULL 
} 
+1

당신은 비용 배열을 보일 수 있는가? –

답변

2

은 당신이 당신의 예에서이 배열을 :

$expenses = array(
    "exp_user" => "1", 
    "exp_date" => "2016-10-18", 
    "exp_date_request" => "2016-10-18", 
    "exp_client" => "Potato", 
    "exp_provider" => "Miew", 
    "exp_amount" => "1", 
    "exp_currency" => "₪", 
    "exp_budget" => "budget2", 
    "exp_method" => "cc", 
    "exp_frequency" => "Monthly", 
    "exp_expenditure" => "asdasdas asdas dsa as", 
    "exp_charge_client" => NULL 
); 

당신은 insert_batch에서 사용할 수 없습니다 이것은 내가 삽입 할 노력하고있어의 예입니다 함수 (insert_batch 함수는 두 번째 매개 변수로 배열의 데이터 배열을 가져 오기를 기대하기 때문에).

기본적으로 insert_batch 함수를 사용하면 insert 함수를 반복하지 않고도 여러 행을 삽입 할 수 있습니다.

$expenses = array(
    array(
     "exp_user" => "1", 
     "exp_date" => "2016-10-18", 
     "exp_date_request" => "2016-10-18", 
     "exp_client" => "Potato", 
     "exp_provider" => "Miew", 
     "exp_amount" => "1", 
     "exp_currency" => "₪", 
     "exp_budget" => "budget2", 
     "exp_method" => "cc", 
     "exp_frequency" => "Monthly", 
     "exp_expenditure" => "asdasdas asdas dsa as", 
     "exp_charge_client" => NULL 
    ), 
    array(
     "exp_user" => "1", 
     "exp_date" => "2016-10-18", 
     "exp_date_request" => "2016-10-18", 
     "exp_client" => "Potato", 
     "exp_provider" => "Miew", 
     "exp_amount" => "1", 
     "exp_currency" => "₪", 
     "exp_budget" => "budget2", 
     "exp_method" => "cc", 
     "exp_frequency" => "Monthly", 
     "exp_expenditure" => "asdasdas asdas dsa as", 
     "exp_charge_client" => NULL 
    ), 
    array(
     "exp_user" => "1", 
     "exp_date" => "2016-10-18", 
     "exp_date_request" => "2016-10-18", 
     "exp_client" => "Potato", 
     "exp_provider" => "Miew", 
     "exp_amount" => "1", 
     "exp_currency" => "₪", 
     "exp_budget" => "budget2", 
     "exp_method" => "cc", 
     "exp_frequency" => "Monthly", 
     "exp_expenditure" => "asdasdas asdas dsa as", 
     "exp_charge_client" => NULL 
    ) 
); 

을 그리고 지금은 insert_batch를 사용하는 의미가 있습니다 : 당신은 단지에 대한 다차원 배열을 사용할 수 있습니다.

당신은 당신이 insert 기능을 사용할 수 있습니다 삽입 할 만 한 기록이있는 경우 :

$this->db->insert('expenses', $expenses); 

을 또는 호출을 변경 :

$this->db->insert_batch('expenses', array($expenses)); 
관련 문제