codeigniter last query print example
In this article, we will inform you how to print the last query in Codeigniter. 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 amount of query 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
1 2 3 4 5 6 7 | 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
1 | select * from article where id=10 |
Read Also: how to get last inserted id in codeigniter
Please follow and like us: