CodeIgniter Forums
Close connection - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Close connection (/showthread.php?tid=71473)

Pages: 1 2


RE: Close connection - omid_student - 08-19-2018

(08-18-2018, 04:03 AM)InsiteFX Wrote: You would need to keep track of your query caches maybe in an array etc;

Then you could just grab it from your array etc; Then delete that special one.

Can i get query string after run it?
Example:
$this->db->where('ID','1');
$res = $this->db->get('user');
echo $this->db->get_compiled_select(); //here i need last query string


RE: Close connection - InsiteFX - 08-19-2018

Did you try using:

PHP Code:
$lastQuery $this->db->last_query() 

The compiled method only allow getting insert, update and delete methods.


RE: Close connection - omid_student - 08-19-2018

(08-19-2018, 03:17 AM)InsiteFX Wrote: Did you try using:

PHP Code:
$lastQuery $this->db->last_query() 

The compiled method only allow getting insert, update and delete methods.

Oh yes it is returning last query
So i have to save query for when i need remove cache
Thanks


RE: Close connection - whutboy - 08-21-2018

(08-17-2018, 04:21 AM)kaitenz Wrote:
(08-17-2018, 04:07 AM)omid_student Wrote: Hi
Is it important for close connection after query?
Example
$res = $this->db->query('')->result_array();
$this->db->close();

Also i have other question
How do i can delete cache only for special query?
at the moment we can delete all cache

AFAIK, Query builder automatically close the database after use (correct me if I'm wrong)

For special queries, assign your special query to a variable:
PHP Code:
$special_query $this->db->query(); 

Then if you want to use 
PHP Code:
$this->db->flush_cache(); 

You can still use your special query:
PHP Code:
$special_query->result(); 

But I didn't try this before (but I use query caching a lot), so try it for yourself.
AFAIK, Query builder automatically close the database after use 
== Agree with you,but I can not find the code , can you tell me when and where did query builder automatically close the database connection?


RE: Close connection - omid_student - 08-21-2018

(08-18-2018, 04:03 AM)InsiteFX Wrote: You would need to keep track of your query caches maybe in an array etc;

Then you could just grab it from your array etc; Then delete that special one.

Yes Thank you