/** * 写入缓存 * @access public * @param string $name 缓存变量名 * @param mixed $value 存储数据 * @param int $expire 有效时间 0为永久 * @return boolen */ public function set($name, $value, $expire = null) { Debug::record('cache_write', 1); if (is_null($expire)) { $expire = $this->options['expire']; } $filename = $this->filename($name); $data = serialize($value); if (C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { //数据压缩 $data = gzcompress($data, 3); } if (C('DATA_CACHE_CHECK')) { //开启数据校验 $check = md5($data); } else { $check = ''; } $data = "<?php\n//" . sprintf('%012d', $expire) . $check . $data . "\n?>"; $result = file_put_contents($filename, $data); if ($result) { if ($this->options['length'] > 0) { // 记录缓存队列 $this->queue($name); } clearstatcache(); return true; } else { return false; } }
/** * 执行语句 * @access public * @param string $str sql指令 * @return integer|false */ public function execute($str) { $this->initConnect(true); if (!$this->_linkID) { return false; } $this->queryStr = $str; //释放前次的查询结果 if ($this->queryID) { $this->free(); } Debug::record('db_write', 1); // 记录开始执行时间 Debug::mark('queryStartTime'); $result = mysql_query($str, $this->_linkID); $this->debug(); if (false === $result) { $this->error(); return false; } else { $this->numRows = mysql_affected_rows($this->_linkID); $this->lastInsID = mysql_insert_id($this->_linkID); return $this->numRows; } }