博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP实体层基础类
阅读量:5060 次
发布时间:2019-06-12

本文共 2556 字,大约阅读时间需要 8 分钟。

PHP实体层基础类

class BaseModel    {        private $tableName;        private $fields=array();        function __construct()        {            $this->tableName=rtrim(get_class($this),'M');        }        function __get($n)        {            return($this->$n);        }        function __set($n, $value)        {            $this->$n = $value;            $this->fields[$n]=$value;        }        function Add()        {            $f='';            $f1='';            $arrKeys=array_keys($this->fields);            foreach($arrKeys as $row)            {                $f.=$row.',';                $f1.=':'.$row.',';            }            $f=rtrim($f,',');            $f1=rtrim($f1,',');            $sql='insert into '.$this->tableName.'('.$f.') values('.$f1.')';            //echo $sql;            global $dbh;            return $dbh->edit($sql,$this->fields);        }        function Update($sql_where,$params=array())        {            $f='';            $f1='';            $arrKeys=array_keys($this->fields);                    foreach($arrKeys as $row)            {                $f.=$row.'=:'.$row.',';            }            $f=rtrim($f,',');            $sql='update '.$this->tableName.' set '.$f.' where '.$sql_where;                        $arrKeys1=array_keys($params);            foreach($arrKeys1 as $row)            {                $this->fields[$row]=$params[$row];            }                        global $dbh;            return $dbh->Edit($sql,$this->fields);        }                function Delete($sql_where,$params=array())        {            $sql='delete from '.$this->tableName.' where '.$sql_where;            //echo $sql;                        global $dbh;            return $dbh->Edit($sql,$params);        }    }

实体层:

class proM extends BaseModel{
private $proName; private $proDetail; private $proPic; private $proPic1; private $proAttr; private $proTaxis; private $proIsHome; private $proIsTJ; private $proIsCTJ; private $proIsDel; private $proAddTime; private $proisHot; private $proisPorClass; private $proisYN; private $proGL; private $proSeoT; private $proSeoK; private $proSeoD; private $proBH; private $FK_proClass; private $proModel; private $proPrice; private $proDiscount; private $proHit; private $proURL; private $proisKdWords; private $proisKdDone; private $proFL;}

使用:

$m=new proM();$m->proName='代码';$m->proDetail='php开发';$m->Update('proID=:proID',array(proID=>1));

 

转载于:https://www.cnblogs.com/suger/p/3458029.html

你可能感兴趣的文章
sqlite的坑
查看>>
digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
查看>>
linux swoole
查看>>
An Easy Problem?! - POJ 2826(求面积)
查看>>
【题解】[P4178 Tree]
查看>>
Jquery ui widget开发
查看>>
css3实现循环执行动画,且动画每次都有延迟
查看>>
更改git仓库地址
查看>>
有标号DAG计数 [容斥原理 子集反演 组合数学 fft]
查看>>
Recipe 1.4. Reversing a String by Words or Characters
查看>>
Rule 1: Make Fewer HTTP Requests(Chapter 1 of High performance Web Sites)
查看>>
sql注入
查看>>
「破解」Xposed强
查看>>
Linux 平台下 MySQL 5.5 安装 说明 与 示例
查看>>
src与href的区别
查看>>
ABAP工作区,内表,标题行的定义和区别
查看>>
《xxx重大需求征集系统的》可用性和可修改性战术分析
查看>>
Python 中 创建类方法为什么要加self
查看>>
关于indexOf的使用
查看>>
【转】JS生成 UUID的四种方法
查看>>