【发布时间】:2017-06-30 06:51:58
【问题描述】:
我在数据库中添加多行。
我在 codeigniter 中使用insert_batch。
我看到了一些 SO 问题,但没有明白我做错了什么。
我使用foreachloop 创建了一个数组,但出现此错误。
这是foreachloop:
foreach($add as $data){
$new_add[] = array(
'col1'=>$data['col1'],
'col2'=>$data['col2'],
'col3'=>$data['col3'],
'col4'=>$data['col4'],
'col5'=>$data['col5'],
'col6'=>$data['col6']
);
}
After Loop 这是我在它之后得到的数组:
Array
(
[0] => Array
(
[col1] => col1_data
[col2] => col2_data
[col3] => col3_data
[col4] => col4_data
[col5] => col5_data
[col6] => col6_data
)
[1] => Array
(
[col1] => col1_data
[col2] => col2_data
[col3] => col3_data
[col4] => col4_data
[col5] => col5_data
[col6] => col6_data
)
)
插入批量查询:
$this->db->insert_batch('test', $new_add);
感谢此评论,我知道我做错了什么。 comment 我在这里犯了一个基本错误,我想使用
insert_batch,但不知何故我忘了在查询中添加它。
错误:
遇到了 PHP 错误
严重性:通知
消息:数组到字符串的转换
文件名:数据库/DB_driver.php
行号:1476
回溯:
文件: D:\opt\wamp\www\yo_builder\application\controllers\Instalment.php 行:85 功能:插入
文件:D:\opt\wamp\www\yo_builder\index.php 行:315 功能: 需要一次
这是第二个错误。
错误号:1064
您的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 靠近第 1 行的 '0, 1) VALUES (Array, Array)'
INSERT INTO
test(0, 1) 值(数组,数组)文件名:D:/opt/wamp/www/yo_builder/system/database/DB_driver.php
行号:691
【问题讨论】:
-
您遇到的错误是什么?
-
我已在问题中添加。 @KetanSolanki
-
发布完整代码
-
@AbdullaNilam 先生,这里没有什么可补充的。我已经添加了我所做的。
-
您正在根据您的代码使用插入。使用 insert_batch
标签: arrays codeigniter foreach