In this article, we will discuss how to insert Single and Multiple records from the MySQL database using the CodeIgniter framework(Codeigniter Single and Multiple records Insert Query). if you want to insert single data into the database then we can use the Insert Query method and if you want to insert multiple records into the database then we can use the insert_batch Query Method.
so you can see the following two ways for Codeigniter to insert database records.
Insert Single Record in CodeIgniter
In this step, we will insert a single row in CodeIgniter. so we will use the Insert Query method for the below example, You can see the following below example.
$data = array( 'title' => $this->input->post('txtTitle'), 'category' => $this->input->post('txtCategory'), 'description' => $this->input->post('txtDescription') ); $this->db->insert('product', $data);
Insert Multiple Records in CodeIgniter
In this step, we will insert multiple rows in CodeIgniter. so we will use the insert_batch Query method for the below example, You can see the following below example.
$data = array( array( 'title' => $this->input->post('txtTitle0'), 'category' => $this->input->post('txtCategory0'), 'description' => $this->input->post('txtDescription0') ), array( 'title' => $this->input->post('txtTitle1'), 'category' => $this->input->post('txtCategory1'), 'description' => $this->input->post('txtDescription1') ) }; $this->db->insert('product', $data);