CodeIgniter Insert Query-how to run Insert Query in CodeIgniter

In this post we will show you how CodeIgniter Insert Query run. we will show you how to run Insert Query in CodeIgniter with query(), With Query Bindings, Standard Insert, insert_string(), insert_batch(), Escaping Insert Queries, Get Inserted ID, Get Affected Rows.

CodeIgniter “Insert” query execute by following functions

  • $this->db->query()
  • Insert With Query Bindings
  • Standard Insert
  • $this->db->insert_string()
  • $this->db->insert_batch()
  • Escaping Insert Queries
  • Get Inserted ID
  • Get Affected Rows

CodeIgniter Insert Query with $this->db->query()

Program 1:

Program 2:

CodeIgniter Insert Query with Standard Insert

CodeIgniter Insert Query with $this->db->insert_string()

Note : Values are automatically producing and escaped safer queries.

CodeIgniter Insert Query with $this->db->insert_batch()

CodeIgniter Insert Query with Escaping Insert Queries

This function determines the data type so that it can escape only string data. It also automatically adds single quotes around the data so we do not have to ::

CodeIgniter Insert Query with $this->db->escape_str()

This function escapes the data passed to it, regardless of type. Most of the time we will use the above function rather than this one. Use the function like this ::

CodeIgniter Insert Query with Get Inserted ID

The insert use ID number when performing database inserts.

CodeIgniter Insert Query with Get Affected Rows

Displays the number of affected rows, when doing “write” type queries (insert, update, other query.).

You also like codeigniter select query and codeigniter join tables and Codeigniter Delete Query