跳至 [1] [2] [全屏预览] , order => , limit => , group => , having => ); public function __construct($tablename){ $this -> tablename = $tablename; try{ $this -> link = mysqli_connect(hostname,username,password,dataname); mysqli_set_charset($this -> link,utf8); }catch(exception $e){ echo 数据库连接失败; } $this -> desc(); } public function __destruct(){ mysqli_close($this -> link); } public function desc(){ $sql = desc {$this -> tablename}; ; $res = mysqli_query($this -> link,$sql); $arr = mysqli_fetch_all($res,mysqli_assoc); for($i = 0 ;$i zd = $brr; return $brr; } public function __call($name,$value){ $name = strtolower($name); if(array_key_exists($name,$this -> method)){ if($name == 'order'){ $this -> method['order'] = order by .$value[0]; }elseif($name == 'group'){ $this -> method['group'] = group by .$value[0]; }else{ $this -> method[$name] = {$name} .$value[0]; } }else{ return the method is not found!; } return $this; } public function method(){ return {$this -> method['where']} {$this -> method['order']} {$this -> method['limit']} {$this -> method['group']} {$this -> method['having']}; ; } public function find($a=*){ if(in_array({$a},$this -> zd) || $a == *){ $sql = select {$a} from {$this -> tablename} {$this -> method()} ; }else{ $sql = select * from {$this -> tablename}; } //return $sql; $res = mysqli_query($this -> link,$sql); $arr = mysqli_fetch_all($res,mysqli_assoc); return $arr; } }
2. [代码][php]代码 跳至 [1] [2] [全屏预览] where(name = 'zhu')->limit(5,10); var_dump($a -> find(name));