zoukankan      html  css  js  c++  java
  • MYSQLI

    <?php
    //模型类
    class Model {
    	//数据库连接
    	private $_conn = NULL;
    	//where语句
    	private $_where = NULL;
    	//表名称
    	private $_tableName = NULL;
    
    	//构造方法,接收表名称
    	public function __construct($tabName){
    		//给属性赋值
    		$this->_tableName = $tabName;
    		//连接数据库
    		$this->_conn = mysqli_connect('localhost', 'root', '12345678', 'test');
    		//设置字符集编码
    		mysqli_set_charset($this->_conn, 'set names utf8');
    	}
    
    	//where方法
    	public function where($whe){
    		//判断是否为空值
    		if ( empty($whe) ) {
    			$this->_where = NULL;
    		} else {
    			$this->_where = ' where ' . $whe;	
    		}
    		//返回对象
    		return $this;
    	}
    
    	//select方法
    	public function select(){
    		//存储数据
    		$dataArr = array();
    		//构造sql语句
    		$sql = 'select * from tp_' . strtolower($this->_tableName) . $this->_where;
    		//执行sql,获取句柄
    		$resHandle = mysqli_query($this->_conn, $sql);
    		//返回结果集
    		while ( !!$res = mysqli_fetch_array($resHandle, MYSQLI_ASSOC )) {
    			$dataArr[] = $res;
    		}
    		//返回数据
    		return $dataArr;
    	}
    
    	//其余方法,待补充......
    	
    }
    
    
    $user = new Model('User');
    $result = $user->where('id > 10')->select();
    print_r($result);
    
  • 相关阅读:
    java中变量的内存分配
    类加载器的双亲委派机制
    缓存行对齐
    缓存一致性与MESI协议
    Mysql优化之join优化
    MySQL crc32 & crc64函数 提高字符串查询效率
    线程不安全
    学习爱上 systemd
    Ubuntu如何备份和恢复系统
    redis报错overcommit_memory is set to 0
  • 原文地址:https://www.cnblogs.com/KTblog/p/5175197.html
Copyright © 2011-2022 走看看