/** * [_query 组合SQL语句 并调用query方法执行 query方法需要被实现] * @param [type] $method [方法类型] * @param string $id [主键ID 可选] * @return [type] [array] */ protected function _query($method, $id = '', $use_mem = true) { if (is_int($id)) { if (empty($this->db_sql['where'])) { $this->db_sql['where'] = ' WHERE ' . $this->pk . '=' . $id; } else { $this->db_sql['where'] .= ' AND ' . $this->pk . '=' . $id; } } elseif (!empty($id)) { $this->exception('该参数可选,但只能是整数!'); } $sql = $method . ' ' . ($method == 'select' ? $this->db_sql['field'] : '') . ' FROM ' . $this->db_table . $this->parseSql(); /* 是否使用memcache */ if ($method == 'select' && defined('MEMCACHE') && MEMCACHE === true && $use_mem) { $mem = new MemcacheModel(); if ($mem->check_connect()) { $data = $mem->getCache($sql); if ($data) { return $data; } else { $result = $this->query($sql, $method); $expire = defined('MEM_EXPIRE') ? MEM_EXPIRE : 180; $mem->addCache($sql, $result, $expire); return $result; } } } return $this->query($sql, $method); }
} DEBUG::addmsg('<b>' . $className . '</b>类', 1); //在Debug消息中显示自动包含的类 } //判断是否开启了Smarty页面静态化缓存 if (CSTART == 0) { Debug::addmsg('<font color="red">没有开启Smarty页面静态化缓存!</font>(但可以使用)'); } else { Debug::addmsg('<font color="green">开启了Smarty页面静态化缓存,实现页面静态化!</font>'); } //启用Memcache缓存 if (!empty($memServers)) { //判断是否设置config了Memchache的变量或数组 if (extension_loaded('memcache')) { //判断是否安装了Memcache缓存模块 $mem = new MemcacheModel($memServers); //判断Memcache缓存服务器是否有异常 if (!$mem->mem_connect_error()) { Debug::addmsg('<font color="red">连接Memcache服务器失败,请检查!</font>'); } else { define('USEMEM', true); //设置Memcahce开启的常量 Debug::addmsg('<font color="green">启用Memcache服务器</font>'); } } else { Debug::addmsg('<font color="red">PHP没有安装Memcache扩展模块,请先安装!</font>'); } } else { Debug::addmsg('<font color="red">没有使用Memcache缓存服务器!</font>(为了程序的速度,建议使用Memcache缓存服务器)'); } //如过开启了Memcache,则将Session信息保存在Memcache缓存服务器中