/** * 执行一条sql语句 * * @param string $sql sql语句 * @param bool $cache 是否缓存 * @return ResultSet */ public function query($sql, $cache = false) { // 读缓存 if ($cache) { $cache = new Cache(); $rtn = $cache->get($sql); if ($rtn) { return unserialize($rtn); } } // 读数据库 switch (DBManager::workingMode()) { case DBManager::MODE_PDO: $rs = $this->_link->query($sql); break; case DBManager::MODE_SQLI: $rs = $this->_link->query($sql); break; case DBManager::MODE_SQL: $rs = mysql_query($sql, $this->_link); break; default: $rs = false; break; } $rtn = new ResultSet($rs, $sql, $cache); return $rtn; }
/** * 构造函数 * * @param mysqli_result | result set | bool $rs * @param string $sql 对应的sql语句 * @param bool $cache 是否缓存 */ public function __construct($rs, $sql, $cache) { $this->_rs = $rs; $this->_seekIndex = 0; // 缓存 if ($cache && !is_bool($rs)) { $cache = new Cache(); $cache->set($sql, serialize($this)); } }