Sometimes, we want to insert multiple rows from an array using the CodeIgniter framework and PHP.
In this article, we’ll look at how to insert multiple rows from an array using the CodeIgniter framework and PHP.
How to insert multiple rows from an array using the CodeIgniter framework and PHP?
To insert multiple rows from an array using the CodeIgniter framework and PHP, we can use the insert_batch
method.
For instance, we write
$data = [
[
"title" => "My title",
"name" => "My Name",
"date" => "My date",
],
[
"title" => "Another title",
"name" => "Another Name",
"date" => "Another date",
],
];
$this->db->insert_batch("mytable", $data);
to call insert_batch
with the table name string and the $data
array to insert as rows into 'mytable'
.
Conclusion
To insert multiple rows from an array using the CodeIgniter framework and PHP, we can use the insert_batch
method.