您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

数据库实例化操作的代码优化写法,核心种进行精简了…

2024/4/24 10:16:56发布3次查看
数据库实例化操作的代码优化写法,核心类进行精简了……
本帖最后由 xjl756425616 于 2013-07-16 16:59:50 编辑 class activerecord
{
    public $table;
    public $data;
    public $obj;    
    public function __construct($table)
    {
     $this->table = $table;
        $this->data  = array();        
        $this->obj = '';
        $this->connect();
    }
    public function connect()
    {
        $config = array_change_key_case(require(conf/config.php));
        if ((!empty($config['db_host'])) && (!empty($config['db_user'])) && (!empty($config['db_name']))) {
            $db_host = $config['db_host'];
            $db_user = $config['db_user'];
            $db_pwd  = $config['db_pwd'];
            $db_name = $config['db_name'];
            $con     = mysql_connect($db_host, $db_user, $db_pwd);
            mysql_select_db($db_name, $con);
            mysql_query(set names utf8);
        }
    }
    public function __set($name, $value)
    {
        $this->data[$name] = $value;
        if(is_object($this->obj)) {
         $this->obj->$name = $value;
       }
    }
    public function __get($name)
    {
     if(is_object($this->obj)) {
         return $this->obj->$name;
       }
    }
    public function add()

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录