In this article, we will inform you how to print last query in Codeigniter(codeigniter print last query example). Codeigniter provides an inbuilt database class. so we can easily print the last query from the database.
we are use the $this->db->last_query() function for the get last query in Codeigniter. we can also get the query such as select query, create a query, update query, delete query, group by, sub query and join query, etc.
When you run a large number of queries at that time we need to display the query then we can do it using the last_query() function. in this article, we will give you a simple example of how to get the last query in CodeIgniter. so you can see the below example.
Example
public function article($id) { $this->db->select('*'); $this->db->where('id',$id); $query = $this->db->get("article")->result(); echo $this->db->last_query(); die; }
Output
select * from article where id=10