面向对象select方法
<?php
class Table{
protected $tablename;
protected $arrTable;
protected $w='';//条件属性
protected $field="*";//查询字段
protected $order="";
function __construct($arrTable=''){
$this->tablename=get_class($this);//获取获取当前的对象名
$this->arrTable=$arrTable;
}
function insert(){
echo $this->insertTable();
}
private function insertTable(){
$keys="(";
$values="(";
foreach ($this->arrTable as $key => $value) {
$keys.=$key.",";
$values.="'".$value."',";
}
$keys=substr($keys, 0,-1).")";
$values=substr($values,0,-1).")";
return "insert {$this->tablename} {$keys} values {$values}<br>";
}
function del(){
if ($this->w!=''){//表示没有条件
$delstr="delete from {$this->tablename} where {$this->w}";
}else{
$delstr="delete from {$this->tablename}";
}
echo $delstr."<br>";
}
function where($w=''){
$this->w=$w;
}
function update(){
$updateData="";
foreach ($this->arrTable as $key => $value) {
$updateData.=$key."=".$value.",";
}
$updateData=substr($updateData,0,-1);
if ($this->w=="") {
echo "update {$this->tablename} set {$updateData} <br>";
}else{
echo "update {$this->tablename} set {$updateData} where {$this->w}<br>";
}
}
function select(){
if ($this->w==""){
$select="select {$this->field} from {$this->tablename} {$this->order}";
}else{
$select="select {$this->field} from {$this->tablename} where {$this->w} {$this->order}";
}
echo $select."<br>";
}
//查询字段
function field($field="*"){
$this->field=$field;
}
//排序
function order($order=''){
$this->order=$order;
}
}
/**
*
*/
class User extends Table
{
}
/**
*
*/
class Article extends Table
{
}
/**
*
*/
class Student extends Table
{
}
$Datas=array("username"=>"admin","userpass"=>'admin');
$user1=new User($Datas);
$user1->insert();
$Datas=array("title"=>"admin","author"=>'admin');
$a=new Article($Datas);
$a->insert();
$a->where("title='清远'");
$a->del();
$a->update();
$Datas = array('id' =>'001' ,'name'=>'zhangsan' );
$s1=new Student($Datas);
$s1->insert();
$s1->field("title,author");
$s1->select();
// $iswhere=""
?>
最新文章
- ubuntu16.04(beaglebone) 下vim 和gcc 的信息
- 关于 windows 下 node_modules\node-sass\vendor 的报错解决方法
- 定时器的应用---查询方式---让8个LED灯,左右各4个来回亮
- iOS ARC内存管理
- ASM文件系统
- AC自动机---Keywords Search
- String、StringBuilder、StringBuffer
- python学习day4--python基础--字典
- java中的进制转换方法
- switch语句:适用于一个条件有多个分支的情况---分支语句
- js模态窗口
- ubuntu12.04 残疾人游客
- openstack私有云布署实践【14.2 登录页dashboard-controller(办公网环境)】
- Redis安装及使用笔记
- JSON WEB TOKEN(JWT)的分析
- BZOJ1925 [Sdoi2010]地精部落 动态规划
- 【HttpClient】一个http_post请求例子
- Centos Raid0 与Raid1 的备注
- Scala 中的构造器
- EasyUi – 5.修改$.messager.show() 弹出窗口在浏览器顶部中间出现