Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-28-2008, 03:40 PM
Junior Member
 
Join Date: Mar 2008
Posts: 2
Unhappy Implementation of Zend_Db_Adapter_Mysqli to use Zend_Cache

I've tried to make an implementation of Zend_Db_Adapter_Mysqli that adds a two parameters: bool cache, and int ttl. To specify whether to use caching, and if so how long the cache has to live.

The reason for this implementation is that I want to make it easier to cache database queries.

Code:
PHP Code:
<?php
class Site_Core_Database extends Zend_Db_Adapter_Mysqli
{
    function 
query($sql$bind = array(), $cache false$cache_ttl 3600)
    {
        
// Do we want to use caching?
        
if($cache !== true)
        {
            
// No - perform the query
            
return parent::query($sql, ($bind == null ? array() : $bind));
        } else {
            
// Valid time to live (ttl)?
            
if(!is_numeric($cache_ttl))
            {
                
$cache_ttl 3600;
            }
            
            
// The cache object
            
$cache Zend_Registry::get('cache');
            
            
// Generate cache key
            
$key md5($sql serialize($bind));
            
            
// Can we load the existing result?
            
if(!($result $cache->load($key)))
            {
                
// If not generate a result
                
$db Zend_Registry::get('db');
                
                
// Bind parameters
                
if($bind != null)
                {
                    
$result $db->query($sql$bind);
                } else {
                    
$result $db->query($sql);
                }
                
$cache->save($result$key, array('db'), $cache_ttl);
            }
            return 
$result;
        }
    }
}
?>
It seems though that there are trouble caching/serializing the result sets, because cache fetching fails.

Saving to the cache works fine, but when I reload the page I get this error:

Quote:
Warning: mysqli_stmt::fetch() [function.mysqli-stmt-fetch]: Couldn't fetch mysqli_stmt in [...]/lib/Zend/Db/Statement/Mysqli.php on line 271

Warning: mysqli_stmt::reset() [function.mysqli-stmt-reset]: Couldn't fetch mysqli_stmt in [...]/lib/Zend/Db/Statement/Mysqli.php on line 275
Anyone got a clue what I can do to implement a caching solution this way?

Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:33 PM.