Posted inphp / Codeigniter

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.

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();


public function test_db(){    
	$query = $this->db->get("items");      
	$str = $this->db->last_query();       
	echo "
";    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 "


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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype