最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP實(shí)現(xiàn)基于mysqli的Model基類完整實(shí)例

 更新時(shí)間:2016年04月08日 09:31:56   作者:ruxingli  
這篇文章主要介紹了PHP實(shí)現(xiàn)基于mysqli的Model基類,給出了數(shù)據(jù)庫(kù)基類的完整實(shí)現(xiàn)與使用方法,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)基于mysqli的Model基類。分享給大家供大家參考,具體如下:

DB.class.php

<?php
  //數(shù)據(jù)庫(kù)連接類
  class DB {
     //獲取對(duì)象句柄
     static public function getDB() {
       $_mysqli = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
       if (mysqli_connect_errno()) {
          echo '數(shù)據(jù)庫(kù)連接錯(cuò)誤!錯(cuò)誤代碼:'.mysqli_connect_error();
          exit();
       }
       $_mysqli->set_charset('utf8');
       return $_mysqli;
     }
     //清理,釋放資源
     static public function unDB(&$_result, &$_db) {
       if (is_object($_result)) {
          $_result->free();
          $_result = null;
       }
       if (is_object($_db)) {
          $_db->close();
          $_db = null;
       }
     }
  }
?>

Model.class.php

<?php
  //模型基類
  class Model {
     //執(zhí)行多條SQL語(yǔ)句
     public function multi($_sql) {
       $_db = DB::getDB();
       $_db->multi_query($_sql);
       DB::unDB($_result = null, $_db);
       return true;
     }
     //獲取下一個(gè)增值id模型
     public function nextid($_table) {
       $_sql = "SHOW TABLE STATUS LIKE '$_table'";
       $_object = $this->one($_sql);
       return $_object->Auto_increment;
     }
     //查找總記錄模型
     protected function total($_sql) {
       $_db = DB::getDB();
       $_result = $_db->query($_sql);
       $_total = $_result->fetch_row();
       DB::unDB($_result, $_db);
       return $_total[0];
     }
     //查找單個(gè)數(shù)據(jù)模型
     protected function one($_sql) {
       $_db = DB::getDB();
       $_result = $_db->query($_sql);
       $_objects = $_result->fetch_object();
       DB::unDB($_result, $_db);
       return Tool::htmlString($_objects);
     }
     //查找多個(gè)數(shù)據(jù)模型
    protected function all($_sql) {
       $_db = DB::getDB();
       $_result = $_db->query($_sql);
       $_html = array();
       while (!!$_objects = $_result->fetch_object()) {
          $_html[] = $_objects;
       }
       DB::unDB($_result, $_db);
       return Tool::htmlString($_html);
     }
     //增刪修模型
     protected function aud($_sql) {
       $_db = DB::getDB();
       $_db->query($_sql);
       $_affected_rows = $_db->affected_rows;
       DB::unDB($_result = null, $_db);
       return $_affected_rows;
     }
  }
?>

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP基于pdo操作數(shù)據(jù)庫(kù)技巧總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

长顺县| 左贡县| 甘孜县| 昌吉市| 福建省| 河源市| 盐亭县| 韶山市| 安乡县| 佛教| 丰宁| 安龙县| 仙居县| 襄城县| 北流市| 桂平市| 乐昌市| 郎溪县| 调兵山市| 富阳市| 新余市| 宿松县| 马边| 常山县| 延川县| 楚雄市| 大足县| 池州市| 永和县| 苏州市| 赣州市| 呼伦贝尔市| 乐安县| 上蔡县| 罗山县| 金华市| 汝南县| 普洱| 盐亭县| 济宁市| 图木舒克市|