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

原创
2016-06-13 12:42:16 655浏览

数据库实例化操作的代码优化写法,核心类进行精简了……
本帖最后由 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()

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。