interface IModel{
public static function all();
public static function get($id);
public static function where($condition,$value);
}
class Model implements IModel{
public static $table;
public static $db;
public function __construct(){
self::$db=new MySQL();
}
public static function get($id){
return self::where('id',$id);
}
public static function where($condition,$value){
$sql=sprintf("select * from %s where %s='%s'",self::$table,$condition,$value);
return self::$db->Query($sql);
}
public static function all(){
$sql=sprintf("select * from %s",self::$table);
return self::$db->Query($sql);
}
}
class PostModel extends Model{
public $postid;
public function __construct(){
parent::__construct();
parent::$table='post';
}
}
class CommentModel extends Model{
public $commentid;
public function __construct(){
parent::__construct();
parent::$table='comment';
}
}
$post=new PostModel();
$post::all();
$arr=$post::get('1');
var_dump($arr);
$comment=new CommentModel();
$arr=$comment::get('2');
var_dump($arr);
abstract class DB{
private $IP;
private $user;
private $pwd;
private $name;
private $connection;
abstract public function Execute($sql);
abstract public function Query($sql);
}
class MySQL extends DB{
public function MySQL(){
/*Config*/
$this->IP='*';
$this->ServerID='*';
$this->ServerPassword='*';
$this->DataBaseName='*';
/*End of Config*/
$this->connection=mysqli_connect($this->IP,$this->ServerID,$this->ServerPassword,$this->DataBaseName);
if(!$this->connection){
die('Could not connect'.$this->connection);
}
mysqli_query($this->connection,'set names utf8');
}
public function Execute($sql){
return mysqli_query($this->connection,$sql);
}
public function Query($sql){
$result=mysqli_query($this->connection,$sql);
$arr=array();
while($row=mysqli_fetch_array($result)){
$arr[]=$row;
}
return $arr;
}
public function Close(){
mysqli_close($this->connection);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有