欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實現(xiàn)基于面向?qū)ο蟮膍ysqli擴展庫增刪改查操作工具類

 更新時間:2017年07月18日 09:32:43   作者:青蛙小王子  
這篇文章主要介紹了PHP實現(xiàn)基于面向?qū)ο蟮膍ysqli擴展庫增刪改查操作工具類,結(jié)合實例形式分析了mysqli增刪改查操作類的封裝與使用技巧,需要的朋友可以參考下

本文實例講述了PHP實現(xiàn)基于面向?qū)ο蟮膍ysqli擴展庫增刪改查操作工具類。分享給大家供大家參考,具體如下:

mysqli擴展庫是MySQL擴展庫的改進(jìn)版本,在mysql擴展庫的基礎(chǔ)上提高了穩(wěn)定性和效率,mysqli擴展庫有兩套東西,一套就是面向過程的mysqli另一套是面向?qū)ο蟮膍ysqli。操作方式大體和mysql擴展庫大體一致,這次還是先抽取出來一個操作mysql的工具類,和調(diào)用的類。

1. mysqli擴展庫操作數(shù)據(jù)庫工具類

<?php
 //數(shù)據(jù)庫操作類
 class DBUtil{
  private $host="localhost";
  private $username="root";
  private $password="123456";
  private $dbname="student";
  private $conn;
  public function DBUtil(){
   $this->conn=new mysqli($this->host, $this->username, $this->password,$this->dbname) or die($this->conn->connect_error);
  }
 //查詢
  public function query($sql){
   $all= $this->conn->query($sql);
   return $all;
  }
 //插入,修改,刪除
  public function otherOperate($sql){
   if($this->conn->query($sql)){
    if($this->conn->affected_rows>0){
      return "OK";
    }else{
      return "ERROOR";
    }
   }
  }
  public function close(){
   $this->conn->close();
  }
 }
?>

2. 下面是具體的調(diào)用工具類的代碼

<?php
 require_once "MySQLUtil.php";
  /*$sql="select * from m_student";
  $util=new DBUtil();
  $result=$util->query($sql);
  while($row=$result->fetch_assoc()){
   echo "$row[stuName]"."</br>";
  }
  $result->free();
  $util->close();*/
  $sql="update m_student set stuName='楊冪' where id=3";
  $util=new DBUtil();
  $result=$util->otherOperate($sql);
  echo $result;
  $util->close();
?>

如果要用到其他方法可以查閱php開發(fā)文檔。

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysqli數(shù)據(jù)庫程序設(shè)計技巧總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

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

相關(guān)文章

最新評論