Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // changed by Doru Brad
- // email me at dorubrad@gmail.com
- // this will cache queries using the opencart cache
- // just replace your db.php file with this one under system->library
- class DB {
- private $driver;
- private $cache;
- private $cachedquery;
- public function __construct($driver, $hostname, $username, $password, $database) {
- $this->cache = new Cache(DB_CACHED_EXPIRE);
- $file = DIR_DATABASE . $driver . '.php';
- if (file_exists($file)) {
- require_once($file);
- $class = 'DB' . $driver;
- $this->driver = new $class($hostname, $username, $password, $database);
- } else {
- exit('Error: Could not load database driver type ' . $driver . '!');
- }
- }
- public function query($sql) {
- $md5query = md5($sql);
- if ($query = $this->cache->get('sql_' . $md5query))
- {
- if ($query->sql == $sql)
- {
- if ($resetflag = $this->cache->get('sql_globalresetcache'))
- {
- if ($resetflag <= $query->time)
- {
- $this->cachedquery = $query;
- return $query->return;
- };
- }
- else
- {
- $this->cachedquery = $query;
- return $query->return;
- };
- }
- }
- $return = $this->driver->query($sql);
- $query = new stdClass();
- $query->return = $return;
- $query->sql = $sql;
- $query->time = time();
- unset($this->cachedquery);
- $this->cache->set('sql_' . $md5query, $query);
- return $return;
- }
- public function escape($value) {
- return $this->driver->escape($value);
- }
- public function countAffected() {
- return $this->driver->countAffected();
- }
- public function getLastId() {
- return $this->driver->getLastId();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement