当前位置: 首页 > news >正文

山西最新疫情更新清远网站seo

山西最新疫情更新,清远网站seo,赌博网站建设,万宁建设局网站一、实现功能,数据表前缀、alias、model、table、join方法实现 二、表前缀实现 1、config.php增加表前缀 DB_PEX>fa_,//数据库前缀 2、增加表前缀方法function.php function model($table){$modelnew ModelBase($table,config("DB_PEX"));return $m…

一、实现功能,数据表前缀、alias、model、table、join方法实现

 

 二、表前缀实现

1、config.php增加表前缀
 'DB_PEX'=>'fa_',//数据库前缀
 2、增加表前缀方法function.php
function model($table){$model=new  ModelBase($table,config("DB_PEX"));return $model;
}
function table($table){return  new  ModelBase($table);
}
3、PDO数据表增加表前缀ModelBase.php
    private $pex="";//表前缀public function __construct($table=null,$pex=""){$this->pex=$pex;if($table){$this->table=$this->pex.$table;}if(!$this->table){die("no table" );}$this->_connect();$this->_opt();}

三、alias数据表别名和join实现实现ModelBase.php

    private function _opt(){$this->opt=array('filed'=>'*','where'=>'','group'=>'','having'=>'','order'=>'','limit'=>'','alias'=>'','join'=>'',);}public function alias($as){$this->opt['alias']=  ' as '.$as." ";return $this;}public function join($join,$condition,$type=''){$this->opt['join']=  " {$type} join ".$this->pex.trim($join)." on {$condition}";return $this;}public function select(){$sql = "SELECT ".$this->opt['filed']. " FROM ".$this->table.$this->opt['alias'].$this->opt['join'].$this->opt['where'].$this->opt['group'].$this->opt['having'].$this->opt['order'].$this->opt['limit'];$stmt = $this->pdo->prepare($sql);$stmt->execute();return $stmt->fetchAll(PDO::FETCH_ASSOC);}

四、控制器实现,数据表前缀、alias、model、table、join方法查询

 public function index(){$data= model("test")->filed('t.*,r.role')->alias('t')->join('role r','t.id=r.testId','left')->select();var_dump($data);$data= table("fa_test")->select();var_dump($data);}

五、完整ModelBase.php代码

<?php
class ModelBase
{public $pdo = NULL;public $table = NULL;public $opt;private $pex="";//表前缀public function __construct($table=null,$pex=""){$this->pex=$pex;if($table){$this->table=$this->pex.$table;}if(!$this->table){die("no table" );}$this->_connect();$this->_opt();}private function _connect(){if($this->pdo){return true;}$host = config('DB_HOST');$db = config('DB_DATABASE');$user = config('DB_USER');$pass =config('DB_PWD');$dsn = "mysql:host=$host;dbname=$db;charset=utf8";try {$this->pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);} catch (PDOException $e) {die("数据库连接失败: " . $e->getMessage());}}private function _opt(){$this->opt=array('filed'=>'*','where'=>'','group'=>'','having'=>'','order'=>'','limit'=>'','alias'=>'','join'=>'',);}public function alias($as){$this->opt['alias']=  ' as '.$as." ";return $this;}public function join($join,$condition,$type=''){$this->opt['join']=  " {$type} join ".$this->pex.trim($join)." on {$condition}";return $this;}public function where($where){$this->opt['where']=  ' WHERE '.$where;return $this;}public function order($order){$this->opt['order']=  ' ORDER BY '.$order;return $this;}public function group($group){$this->opt['group']=  ' GROUP BY '.$group;return $this;}public function having($having){$this->opt['having']=  ' having '.$having;return $this;}public function filed($filed){$this->opt['filed']= $filed;return $this;}public function limit($limit){$this->opt['limit']=  ' limit '.$limit;return $this;}public function select(){$sql = "SELECT ".$this->opt['filed']. " FROM ".$this->table.$this->opt['alias'].$this->opt['join'].$this->opt['where'].$this->opt['group'].$this->opt['having'].$this->opt['order'].$this->opt['limit'];$stmt = $this->pdo->prepare($sql);$stmt->execute();return $stmt->fetchAll(PDO::FETCH_ASSOC);}public function find(){$data=$this->limit(1)->select();return current($data);}public function delete(){$sql = "DELETE FROM ".$this->table.$this->opt['where'];$stmt = $this->pdo->prepare($sql);$stmt->execute();return $stmt->rowCount();}public function insert( $data) {// 准备SQL语句$fields = implode(', ', array_keys($data));$values = ':' . implode(', :', array_keys($data));$sql = "INSERT INTO ". $this->table." (".$fields.") VALUES (".$values.")";// 绑定参数并执行SQL语句$stmt = $this->pdo->prepare($sql);foreach ($data as $key => $value) {$stmt->bindValue(':' . $key, $value);}return $stmt->execute();}public function update( $data){if(empty($this->opt['where'])) die('更新语句必须有were条件');$up='';foreach ($data as $k=>$v){$up.="`".$k."`='".$v."'";}$sql="update  ".$this->table.' set '.$up.$this->opt['where'];$stmt = $this->pdo->prepare($sql);$stmt->execute();return $stmt->rowCount();}}

http://www.hkea.cn/news/882329/

相关文章:

  • b2c电子商务网站系统下载专业网站seo推广
  • 引流推广的方法seo诊断工具
  • 平阴县建设工程网站直通车推广怎么做
  • 网站开发外包不给ftp高佣金app软件推广平台
  • 太原适合网站设计地址百度用户服务中心客服电话
  • 济南源码网站建设长沙网站seo推广公司
  • 北京网站制作17页和业务多一样的平台
  • 无锡市住房城乡建设委网站简单网页设计模板html
  • 武汉市大型的网站制作公司网站ip查询
  • 做仪表行业推广有哪些网站电商网站设计
  • 动静分离网站架构百度售后客服电话24小时
  • 做汽车配件生意的网站佛山seo关键词排名
  • 创意建站推荐百度做广告多少钱一天
  • 巴中网站建设公司百度seo怎么做网站内容优化
  • 查网站备案名称上海网络营销seo
  • 人是用什么做的视频网站网络营销方案设计毕业设计
  • 建设网站考虑因素关键词优化是怎么弄的
  • 陕西营销型网站建设推广普通话的内容简短
  • 做配电箱的专门网站百度指数属于行业趋势及人群
  • 学做网站的网站重庆seo整站优化报价
  • 保定网站设计概述seo推广软件排名
  • 查pv uv的网站网络营销推广服务
  • 怎样让客户做网站优化 保证排名
  • 企业营销型网站做的好网络营销的有哪些特点
  • 网站开发 合同兰州快速seo整站优化招商
  • 网站开发技术现状深圳网络营销推广培训
  • 知名网络公司有哪些河北网站seo
  • 学做网站多少钱关键词难易度分析
  • 传奇如何做网站网站建设策划书案例
  • 龙岗 网站建设深圳信科最好用的搜索神器