how to get raw query in codeigniter

Today, We want to share with you get last query in codeigniter.In this post we will show you print last query in core php, hear for select query in codeigniter controller we will give you demo and example for implement.In this post, we will learn about last query in ci with an example.

codeigniter print query before executing

In this post we will give you information about PHP Codeigniter get last executed query example. Hear we will give you detail about PHP Codeigniter get last executed query exampleAnd how to use it also give you demo for it if it is necessary.

Read Also:  codeigniter last query (last query ci) Examples

PHP Codeigniter get last executed query example

Controller Code:

 * Get All Data from this method.
 * @return Response

public function index()

    $data['data'] = $this->db->get("items")->result();
    $executedQuery = $this->db->last_query();

Free Live Chat for Any Issue


public function test_db(){    
	$query = $this->db->get("items");      
	$str = $this->db->last_query();       
	echo "<pre>";    print_r($str);    

How To Get Last Query In PHP Codeigniter?

public function product()
    $query = $this->db->get("product");
    $str = $this->db->last_query();
    echo "<pre>";


SELECT * FROM `product`


I hope you get an idea about how to get raw query in codeigniter.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.