| function fetch_array($query, $result_type = MYSQL_ASSOC) { |
| return is_resource($query) ? mysql_fetch_array($query, $result_type) : $query[0]; |
| } |
| |
| function query_memcache($sql, $type = '') { |
| global $mem,$memcachelife; |
| |
| $key = md5($sql); |
| if(!($query = $mem->get($key))) { |
| $query = $this->query($sql, $type); |
| while($item = $this->fetch_array($query)) { |
| $res[] = $item; |
| } |
| $query = $res; |
| $mem->set($key, $query , 0, $memcachelife); |
| } |
| return $query; |
| } |
| |
| function query($sql, $type = '') { |
| global $debug, $discuz_starttime, $sqldebug, $sqlspenttimes; |
| |
| $func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ? |
| 'mysql_unbuffered_query' : 'mysql_query'; |
| if(!($query = $func($sql, $this->link)) && $type != 'SILENT') { |
| $this->halt('MySQL Query Error', $sql); |
| } |
| |
| if(substr($sql, 0, 6) == 'SELECT') { |
| echo '<font color="red">Cache SQL</font>:<font color="green">'.$sql.'</font><br /><br />'; |
| } else { |
| echo '<font color="red">Flash SQL</font>:<font color="green">'.$sql.'</font><br /><br />'; |
| } |
| |
| $this->querynum++; |
| return $query; |
| } |