Asked 2 years ago
4 Mar 2022
Views 983
dilip

dilip posted

How to print SQL query in codeigniter ?

I am working on search-related code to find products from the table in the database
but I want to print the query to debug it properly.

 $search = remove_special_characters($search);
		$this->build_query();
		$this->db->like('products.title', $search);
		$this->db->order_by('products.is_promoted', 'DESC');
		$this->db->limit(8);
		$query = $this->db->get('products');
		  $query->result();
echo $this->db->print_query();


i am trying to print query but not sure getting error .

duglus

duglus
answered Mar 4 '22 00:00

use last_query() instead of print_query()

		echo $this->db->last_query();



last_query() will print the last query which is executed.
Post Answer