Thursday 16 April 2020

How to get last executed query in Codeigniter?

Are you want to display last executed query in Codeigniter ?
You can use last_query() function of db class in Codeigniter.


You can use in controller and get output of last executed query:






Example : 


public function get_cities(){  

           $query = $this->db->get("cities"); 


           $str = $this->db->last_query(); 

           echo "<pre>";

           print_r($str);

           exit;

}



Output:


SELECT * FROM `items`







Friday 3 April 2020

Why Codeigniter Shopping Cart doesn't allow any special character in the name?

Codeigniter Cart have some rules for product name in following format :

$product_name_rules = '\w \-\.\:';   (Codeigniter 3).

You can see this rule in Cart Library.

Here no any special character allow in product name. So, need some modification for allow special character. You can add same product name in cart with following modification in your cart class not in default Cart Library.

Add the following syntax before insert cart :


$this->cart->product_name_rules = '[:print:]';


After add this syntax your code looks like :


$this->cart->product_name_rules = '[:print:]';
$this->cart->insert(array());


'[:print:]' - allow to insert product name with special character.