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();
    print_r($executedQuery);
    exit;
}


Example

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

How To Get Last Query In PHP Codeigniter?

public function product()
{
    $this->db->select('*'); 
    $query = $this->db->get("product");
    $str = $this->db->last_query();
    echo "
";
    print_r($str);
}

Output:

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 infinityknow.com 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.

Leave a Comment