0

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

在我的测试中,我尝试了以下方法,一切正常:

$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)具有完全相同数量的元素。知道为什么我会收到此错误吗?

4

2 回答 2

2

你需要在 php中使用implode函数:

$r = implode(",", $tablefields);
于 2012-08-24T11:16:05.633 回答
0

或者

$r = array('field1', 'field2', 'field3');
于 2012-08-24T11:33:03.120 回答