• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do I cache multiple databases (dynamic query)

#1
Hi, 

I have 4 databases in the config. 

my model is something like: 


PHP Code:
function get_total($dbkey){
// this $dbkey is the additioanl databases specified in the config 

$thisdb $this->load->database($dbkeyTRUE);
$thisdb->cache_on();
$query $thisdb->query("select count(*) as total from dbname.tablename"); 
$row 
$query->row();
return 
$row; 
}  


and from the controller, I do something like 



PHP Code:
$this->load->model('mydb') 

$db2total_users 
$this->mydb->get_total("db2"):
$db3total_users $this->mydb->get_total("db3"):
$db4total_users $this->mydb->get_total("db4"):
$db5total_users $this->mydb->get_total("db5"): 


This works fine . with this I am able to connect to 4 additional database and pull all info @ once. 


The issue here is that the $thisdb->cache_on();  on the model is not working. The connection takes the same amount of time even if that line was not there.. and then, I do not see any pages being created on application/cache 

another thing to note, the profiler only shows the main $db query .. for the additional ones, it does not.

so how would I do db query cache here ? 


Thanks
Reply

#2
@admin0,

This statement does not look right:
CURRENT: $query = $thisdb->query("select count(*) as total from dbname.tablename");
SHOULD BE: $query = $this->db->query("select count(*) as total from dbname.tablename");
Reply

#3
(07-05-2018, 09:34 AM)php_rocs Wrote: @admin0,

This statement does not look right:
CURRENT: $query = $thisdb->query("select count(*) as total from dbname.tablename");
SHOULD BE: $query = $this->db->query("select count(*) as total from dbname.tablename");


$this->db . -- is for the default db 
i use the default db for only login and sessions. 

$thisdb is from the model where I pass the db as argument and thus a single model/function allows me to query multiple identical databases in the fly. 

the query/model is working fine .. just caching is not .. unless caching is only for the default db and not for extra dbs
Reply

#4
@admin0,

Caching should work fine unless there is something not declared correctly.
How do you declare the databases in the config file?
Reply

#5
https://www.codeigniter.com/userguide3/d...ching.html

Looking at the setup steps - is the folder writable?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.