CodeIgniter Update Query

In this tutorial you will learn about the CodeIgniter Update Query and its application with practical example.

In CodeIgniter, update() method is used to update existing record in database table. In order to generate update statement, update() method is used along with set() and where() methods in following ways –

Syntax:-

Here,

$table(String):- Table Name

$set(array):- An associative array of column/value for update.

$where(mixed):- It contains where clause

$limit(int):- It contains limit clause

Returns(bool):- It returns TRUE on success and FALSE on failure.

Example:- Let’s say you have a MySQL table named ’employee_master’ with the following fields –
emp_ID, emp_name, emp_email, emp_phone, emp_address, emp_code and emp_dept

Update using $this->db->update()

This is how you can update an existing record into ’employee_master’ table using $this->db->update().

Update with $this->db->where()

This is how you can update an existing record into ’employee_master’ table using $this->db->update() along with $this->db->where().

Update with $this->db->set()

This is how you can update an existing record into ’employee_master’ table using $this->db->update() along with $this->db->set().

Update using $this->db->update_batch()

This is how you can update an existing records into ’employee_master’ table using $this->db->update_batch().

The first parameter will contain the table name, the second is an associative array of values, the third parameter is the where key.

 

In this tutorial we have learn about the CodeIgniter Update Query and its application with practical example. I hope you will like this tutorial.