application/models/mysql_model.php

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Mysql_model extends CI_Model { 

    public function __construct(){
  		parent::__construct();
		$this->cache_time = 3600000;
		$this->cache_path = $this->config->item('cache_path');
		$this->load->driver('cache', array('adapter' => 'file'));
	}

    public function query($table,$sql,$type=1) {
		$name   = $table.md5($table.$sql.$type);
		$result = $this->cache->get($name);
		if (!$result) {
			$query = $this->db->query($sql);
			switch ($type) {
				case 1:
					$result = $query->row_array();
					break;  
				case 2:
					$result = $query->result_array();
					break;  	
				case 3:
					$result = $query->num_rows();
					break; 	
			}
			$this->cache->save($name,$result,$this->cache_time);
		}
		return $result;
	}
	
	public function get_results($table,$where='',$field='*') {
	    $name   = $table.md5('get_results'.$table.$where.$field);
		$result = $this->cache->get($name);
		if (!$result) {
		    if ($where) {
				$this->db->where($where);
			}
			$this->db->select($field);
			$query = $this->db->get($table); 
			$result = $query->result_array();
			$this->cache->save($name,$result,$this->cache_time);
		}
		return $result;
	}
	
	public function get_row($table,$where='',$field='*') {
	    $name   = $table.md5('get_row'.$table.$where.$field);
		$result = $this->cache->get($name);
		if (!$result) {
			if (!$where) return false;
			if (isset($where)) {
				$this->db->where($where);
			}
			$this->db->select($field);
			$query = $this->db->get($table); 
			$result = $query->row_array();
			$result = ($field!='*') && $result ? $result[$field] : $result;
			$this->cache->save($name,$result,$this->cache_time);
后面还有 93 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。