插入的正常数据,字段值没有NULL
~~~
array(15) {
["user"] => string(6) "000243"
["cname"] => string(6) "李杰"
["chief"] => string(9) "代令建"
["big_area"] => string(6) "广东"
["newreg_num"] => int(9)
["neword_num"] => int(1)
["price_pat"] => int(0)
["price_pats"] => int(183)
["regcic_num"] => int(13)
["free_num"] => int(82)
["cicnum_30d"] => int(0)
["has_orders_clinics_num"] => int(82)
["active_clinics_rate"] => string(4) "100%"
["date_sample"] => string(10) "2017-04-21"
["id"] => string(1) "1"
}
~~~
插入的异常数据,字段值有NULL
~~~
array(15) {
["user"] => string(6) "000243"
["cname"] => string(6) "李杰"
["chief"] => string(9) "代令建"
["big_area"] => string(6) "广东"
["newreg_num"] => int(9)
["neword_num"] => int(1)
["price_pat"] => int(0)
["price_pats"] => int(183)
["regcic_num"] => int(13)
["free_num"] => int(82)
["cicnum_30d"] => int(0)
["has_orders_clinics_num"] => int(82)
["active_clinics_rate"] => string(4) "100%"
["date_sample"] => string(10) "2017-04-21"
["id"] => NULL
}
~~~
报错
~~~
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1 [closed]
~~~
the error is clear. you're inserting X columns, but have Y values specified. value counts and field counts MUST match.
e.g. insert into foo (x,y,z) values (1,2) - where's 3?
* * * * *
字段组装的时候可以在拼接之前先取值,做计算,再组装。
批量插入的时候,所有记录的字段数量都必须一致,且不允许有NULL值字段。