/** * 读取SESSION内容 * * @param string $sid 会话唯一标识 * @return string 会话值 */ public function read($sid) { /** * 以数据库方式来处理SESSION */ if ($this->_type == 'db' || $this->_type == 'mdb') { $res = $this->_db->fetch_row("SELECT sData FROM {$this->_opt} WHERE sId = '{$sid}';"); return $res ? $res['sData'] : ''; } /** * 以Memcache缓冲方式来处理SESSION */ if ($this->_type == 'mem') { return $this->_mem->get('session', $sid); } /** * 以文件系统的方式来处理SESSION */ if ($this->_type == 'dir') { $sfile = "{$this->_path}/{$sid[0]}/{$this->_prefix}-{$sid}"; } else { $sfile = "{$this->_path}/{$this->_prefix}-{$sid}"; } if (!file_exists($sfile)) { return ''; } return (string) file_get_contents($sfile); }
/** * 获取数据库中有多少条记录 * * @param string $sql SQL语句 * @return integer 数据记录数 */ private function _amount($sql) { if (stripos($sql, 'GROUP BY') !== false) { $this->_db->query($sql); $row_nu = $this->_db->num_rows(); } else { $res = $this->_db->fetch_row($sql); $row_nu = $res['CNUM']; } $this->_db->free(); $this->amount = $row_nu; return $this->amount; }