<?php
 
class Base_model extends CI_Model {
 
 
        //数据库对象
        public $db;
 
        //数据库工具类
        public $dbutil;
 
        //数据库工厂类
        public $dbforge;
 
        public function __construct()
    {
        // Call the CI_Model constructor
        parent::__construct();
    }
        
        //连接数据库
        public function connectdb()
        {
                if ($this->db !== NULL) {
                        return;
                }
                $data = $this->auto_model->connectdb('default');
                $this->db = $data['db'];
                $this->dbutil = $data['dbutil'];
                $this->dbforge = $data['dbforge'];
        }
 
        //校验数据库
        public function checkdb()
        {
                if ( ! $this->dbutil->database_exists($this->db_name)) {
                        if ( ! $this->dbforge->create_database($this->db_name)) {
                                $this->EFUNC->RUNTIME_ERROR("create database error", $this->db_name);
                        }
                }
                $this->db->db_select($this->db_name);
        }
 
}