【发布时间】:2015-08-30 11:33:39
【问题描述】:
我想用 codeigniter 框架从数组格式中插入数据。
Array ( [run_date] => Array ( [0] => 2015-06-15 11:10 [1] => 2015-06-15 11:10 [2] => 2015-06-15 11:10 [3] => 2015-06-15 11:10 ) [msisdn] => Array ( [0] => 8499270093 [1] => 8599387282 [2] => 6281019183 [3] => 8597375112 ) )
我一直在尝试在 codeigniter 上使用 insert_batch 命令,但它根本不起作用。如下所示。
我的控制器
function insertFromConfirmation() {
$datanew = array(
'run_date' => $this->input->post('run_date'),
'msisdn' => $this->input->post('msisdn')
);
print_r($datanew);
$this->modelMsisdn->insertDataArray($datanew);
}
和我的模特
public function insertDataArray($datanew) {
$this->db->insert_batch('subscription_renewal', $datanew);
}
错误显示:
Error Number: 1054 Unknown column '0' in 'field list' INSERT INTO `subscription_renewal` (`0`, `1`, `2`, `3`) VALUES ('2015-06-15 11:10','2015-06-15 11:10','2015-06-15 11:10','2015-06-15 11:10'), ('8499270093','8599387282','6281019183','8597375112')
文件名:C:\xampp\htdocs\msisdn_tools_new\system\database\DB_driver.php 行号:330
表结构
创建表subscription_renewal(idint(11) NOT NULL AUTO_INCREMENT,msisdnvarchar(32) 字符集 utf8 非空,servicevarchar(64) 字符集 utf8 非空,adnvarchar(8) 字符集 utf8 非空,operatorvarchar(32) 字符集 utf8 非空,channelvarchar(16) 字符集 utf8 非空,statustinyint(4) 非空,descriptionvarchar(20) 字符集 utf8 默认为 NULL,blacklist_statustinyint(4) 非空,date_created日期时间不为空,date_modified日期时间不为空,run_date日期时间默认为空,pricevarchar(30) 默认为空, 主键 (id) ) ENGINE=InnoDB AUTO_INCREMENT=476 默认字符集=latin1
【问题讨论】:
-
('0', '1', '2', '3')检查数据库表字段名称是否正确 -
是的,该字段不是显示的错误,但我想知道该数组格式是如何插入数据库的
-
你能给我看看你的表结构器吗
-
我一直在更新 abdulla 上面的表结构
-
你需要理解你的SQL语句。应该是
INSERT INTO subscription_renewal ('id','run_date','msisdn') VALUES ('0','2015-06-15 11:10','8499270093');不要使用insert_batch。您可以使用 insert_string 和“for each”循环来执行此多行插入
标签: arrays codeigniter