列计数没有';t与具有2个相同长度的数组的行1处的值计数相匹配


Column count doesn't match value count at row 1 with 2 arrays of same length

我正在尝试保存到数据库,我需要实现一个系统,在该系统中,用户可以指定数据必须保存在给定表的哪些字段中。

在我的测试中,我尝试了以下方法,一切都很好:

$v = $rowdata; // array with the data to be saved
$r =  "field1,field2,field3"; // fields of the table in which to save

然后我准备了带有字段名称的数组,并将其放入前一个结构中:

$v = $rowdata; // data to be saved
$r = $tablefields; // fields of the table to populate

但后来我得到了以下信息:

Column count doesn't match value count at row 1

我使用print_r进行了检查,并且这两个数组($rowdata和$tablefields)具有完全相同数量的元素。知道我为什么会犯这个错误吗?

您需要在php:中使用内爆函数

$r = implode(",", $tablefields);

$r = array('field1', 'field2', 'field3');