<?php
/**
* 利用魔术方法__call模拟数据库连贯操作
*/
class DB
{
public $sql=array(
'field'=>'',
'where'=>'',
'order'=>'',
'limit'=>''
);
function __call($name,$args){
$name=strtolower($name);
if(array_key_exists($name,$this->sql)){
$this->sql[$name]=$args[0];
}else{
echo 'Class'.get_class().' do not have a method '.$name;
}
return $this;
}
function select(){
echo "SELECT ".$this->sql['field']." FROM user ".$this->sql['where']." ".
$this->sql['order']." ".$this->sql['limit'];
}
}
$obj =new DB();
$obj->field("id,name,time")
->where("where id>9")
->order('order by id')
->limit(10)
->select();
?>
利用魔术方法__call模拟数据库连贯操作
最新推荐文章于 2021-01-12 00:20:51 发布