Thursday, August 15, 2013

How to empty or truncate mysql table using codeigniter active record?

If you want to empty or truncate a mysql table using Codeigniter active record, use the following code.
To empty
$this->db->empty_table();
This will generate a delete SQL string and runs the query.
// DELETE FROM mytable
To truncate
$this->db->from('mytable'); 
$this->db->truncate(); 
// or 
$this->db->truncate('mytable');
This will generate a truncate SQL string and runs the query.
// TRUNCATE mytable 
Source: http://www.learnhow2do.com/computer/internet/2013/04/13/learn-how-to-empty-or-truncate-table-using-codeigniter-active-record/

No comments:

Post a Comment