面向对象与面向过程的相互转换
此处还是以Model::get()方法和Model::first()方法为例
public static function get($data=[]){//默认是空数组
if(count($data)==0){
$this->getAll();
}else{
$this->getSelect($data);
}
}
public function getAll(){
$sql="select * form".$this->tables;
$this->dao->getAll($sql);}
public function getSelect($data){
$column=implode(','$data);
$sql='select'.$column.'form'.$this->table;
$this->dao->getSelect($sql);
}
//首先转换get方法
function get($data=[]){//默认是空数组
if(count($data)==0){
getAll();
}elsel{
getSelect()
}
}
//接下来转换getAll方法
function getAll(){
$sql="select * form".TABLE_NAME;
mysql_exec($sql);
}
//接下来转换getSelect()方法
function getSelect($data){
$column=implode(','$data);
$sql='select'.$column.'form'.TABLE_NAME;
mysql_exec($sql)
}
//封装mysql的执行的方法
function mysql_exec($sql){
$con = mysql_connect("localhost","root","root");
mysql_query($sql,$con);
}