Codeigniter Single and Multiple records Insert Query
In this article, we will discuss about how to insert Single and Multiple records from the MySQL database using the CodeIgniter framework. 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 insert database record.
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.
1 2 3 4 5 6 | $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.
1 2 3 4 5 6 7 8 9 10 11 12 13 | $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); |
Please follow and like us: