class usermodel{
protected $email='user@163.com';
protected $data=array();
public function __set($k,$v){
$this->data[$k]=$v; //放在一个数组里
}
public function add(){
$sql='insert into table (';
$sql.=implode(',',array_keys($this->data));
$sql.=') values(\'';
$sql.=implode("','",array_values($this->data));
$sql.="')";
return $sql;
}
}
$user=new usermodel();
$user->username='lisi';
$user->email='lisi@163.com';
echo $user->add();
//insert
into table (username,email)
values('lisi','lisi@163.com')
into table (username,email)
values('lisi','lisi@163.com')