/** * 取缓存 * @param $pKey * @param $pVal * @param int $pExp * @return bool */ static function set($pKey, $pVal, $pExp = 3600) { return Cache_Memcache::instance()->set($pKey, $pVal, $pExp); }
/** * 执行SQL,并返回结果 */ function query() { $tArgs = func_get_args(); $tSql = array_shift($tArgs); # 锁表查询 if ($this->_lock) { $tSql .= ' ' . $this->_lock; $this->_lock = ''; } # 使用缓存 if ($this->cache) { $tMem =& Cache_Memcache::instance('default'); if ('md5' == $this->cache['key']) { $this->cache['key'] = md5($tSql . ($tArgs ? join(',', $tArgs) : '')); } if (false !== ($tData = $tMem->get($this->cache['key']))) { return $tData; } } # 查询数据库 $this->db =& self::instance($this->_config); if ($tArgs) { $tQuery = $this->db->prepare($tSql); $tQuery->execute($tArgs); } else { $tQuery = $this->db->query($tSql); } if (!$tQuery) { $this->error = $this->db->errorInfo(); isset($this->error[1]) || ($this->error = array()); return array(); } # 不缓存查询结果 if (!$this->cache) { return $tQuery->fetchAll(PDO::FETCH_ASSOC); } # 设置缓存 $tData = $tQuery->fetchAll(PDO::FETCH_ASSOC); $tMem->set($this->cache['key'], $tData, 0, $this->cache['expire']); $this->cache = array(); return $tData; }