Welcome Guest, Not a member yet? Register   Sign In
Empty result queries when using the CI 'database caching class'
#1

[eluser]Unknown[/eluser]
Hello everyone,

I am having difficulties getting the database caching class of CI to work. It's driving me pretty insane actually. Any help would be greatly appreciated! Smile

Original problem: I need to cache all SELECT queries on the database (to speed the website up)
Original solution: Use CI's caching class
Current problem: I get empty result queries for any queries on databases, other than the default group.

I am using codeigniter 1.7.2 with an MSSQL 2005 database and the Microsoft PHP MSSQL driver. With the CI driver from 'http://www.phrenzy.org/code/sql-server-and-php/'.

In order to illustrate the problem, I have some examples:

When I do this (in my model), caching works and I get a result from the query (where 'meta_db' refers to my default database group in 'settings/database.php'):
Code:
$this->meta_db->cache_on();
$query=$this->meta_db->get('users');
$this->meta_db->cache_off();


But when I do this (replacing 'get' with 'query' method):
Code:
$this->meta_db->cache_on();
$query = $this->meta_db->query('SELECT * FROM users');
$this->meta_db->cache_off();


I get an empty result query. But when I change the name of the DB group from 'meta_db' to 'db', then all of a sudden it works again:
Code:
$this->meta_db->cache_on();
$query = $this->db->query('SELECT * FROM users');
$this->meta_db->cache_off();

So here is a complete overview of what I do:
1.) First I declare the DB objects in the beginning of my model class:
Code:
private $meta_db;
private $codeboek_db;
private $douanelinq_db;

2.) Then I load the DB in the model constructor, based on the groups defined in 'settings/database.php':
Code:
$this->meta_db = $this->load->database('default', TRUE);
$this->codeboek_db = $this->load->database('codeboek_XML', TRUE);
$this->douanelinq_db = $this->load->database('KDL_storage', TRUE);

3.) From that point onwards, I just execute the various queries as described above.

In the 'settings/database.php' file I set the ['cachedir'] property for all the database groups, and files get written to that location (so it is not an access problem). I do not set the ['cache_on'] property, since I enable and disable it manually with 'cache_on()' and 'cache_off()', but enabling it, I get the same results.

I feel perhaps that I am using multiple databases in an incorrect way in my model class?

What could be the problem?
- Is it related to the way I use multiple database groups? --> It should be noted that this works perfect without caching.
- Is it due to the fact that I am using MSSQL with the Microsoft PHP driver?

Any help is greatly appreciated! :lol:




Theme © iAndrew 2016 - Forum software by © MyBB