无法使用 php codeigniter 插入批量记录

Posted

技术标签:

【中文标题】无法使用 php codeigniter 插入批量记录【英文标题】:not able to insert bulk record using php codeigniter 【发布时间】:2019-05-10 20:28:48 【问题描述】:

提供了这个数组,我正在尝试使用 insert_batch 将它插入到表中。

$arrayOfQuestions 包含多个数组,如下所示:

Array
(
    [0] => Array
        (
            [question_desc] => In human beings, partial pressure of carbon dioxide in the inspired and expired air is respectively
            [option_a] => 0.3 and 40 mm Hg
            [option_b] => 0.3 and 32 mm Hg
            [option_c] => 40 and 46 mm Hg
            [option_d] => 40 and 0.3 mm Hg
            [answer] => B
            [diff_level] => 4
            [solution] => Refer answer.
            [chapter_id] => 54
            [inst_id] => 1
            [subject_id] => 68
            [ref_q_id] => 8540371983
        )

    [1] => Array
        (
            [question_desc] => At high altitude, RBCs of human blood will
            [option_a] => Increase in number
            [option_b] => Decrease in number
            [option_c] => Decrease in size
            [option_d] => Increase in size
            [answer] => A
            [diff_level] => 2
            [solution] => At higher altitudes, due to low pressure of atmospheric oxygen, the body has to carry more oxygen than normal in per volume of blood to supply the body constantly. The increased number of RBC in blood ensures the presence of more haemoglobin and thus more oxygen is carried.
            [chapter_id] => 54
            [inst_id] => 1
            [subject_id] => 68
            [ref_q_id] => 8540371983
        )
)

我得到 return true 我在下面尝试过的代码,但数据没有插入到表中..

$result = $this->db->insert_batch('test_temp_question', $arrayOfQuestions);

【问题讨论】:

insert_batch 返回插入的行数或 FALSE。 $result 的实际值是多少? 【参考方案1】:

成功插入数据的使用条件:

if($result>0)
echo"successfull.";

else
echo"not successfull";

【讨论】:

以上是关于无法使用 php codeigniter 插入批量记录的主要内容,如果未能解决你的问题,请参考以下文章

在 Codeigniter 插入数组中使用类似 NOW() 的东西

某些字段的 PHP Codeigniter 批量更新失败

如何在 Codeigniter 中插入动态数据?

PHP CodeIgniter路由插入

使用 Codeigniter 插入忽略

如何在 codeigniter(或 php)中获取插入的新 id? [复制]