人人人妻人人人妻人人人,99精品国产综合久久久久五月天 ,欧美白人最猛性XXXXX,日韩AV无码免费播放

News新聞

業(yè)界新聞動態(tài)、技術(shù)前沿
Who are we?

您的位置:首頁      樂道系統(tǒng)FAQ      php中分頁及SqlHelper類用法實例

php中分頁及SqlHelper類用法實例

標(biāo)簽: 發(fā)布日期:2017-01-12 00:00:00 232
【CLI】利用Curl下載文件實時進度條顯示的實現(xiàn)

本文實例講述了php中分頁及SqlHelper類用法。分享給大家供大家參考,具體如下:

文檔目錄結(jié)構(gòu)如下:

SqlHelper.php代碼如下:

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: lee
 * Date: 13-7-26
 * Time: 下午8:30
 * To change this template use File | Settings | File Templates.
 */
class SqlHelper{
  private $mysqli;
  private static $host="localhost";
  private static $user="root";
  private static $pwd="";
  private static $db="world";
  private $sql=false;
  private $result=false;
  function __construct(){
    $this->mysqli=new MySQLi(self::$host,self::$user,self::$pwd,self::$db);
    if($this->mysqli->connect_error){
      die("連接數(shù)據(jù)庫失??! ".$this->mysql->connect_error);
    }
    $this->mysqli->query("set names utf8");
  }
  function execute_dql_all($sql){
    //執(zhí)行查詢語句
    $arr=array();
    $this->result=$this->mysqli->query($sql) or die ($this->mysql->connect_error);
    //將數(shù)據(jù)轉(zhuǎn)存到$arr數(shù)組中
    while($row=mysqli_fetch_array($this->result,MYSQL_BOTH)){
      $arr[]=$row;
    }
    $this->result->free();
    return $arr;
  }
  function execute_dql_num($sql){
    //執(zhí)行查詢語句
    $arr=array();
    $this->result=$this->mysqli->query($sql) or die ($this->mysql->connect_error);
    //將數(shù)據(jù)轉(zhuǎn)存到$arr數(shù)組中
    while($row=mysqli_fetch_array($this->result,MYSQLI_NUM)){
      $arr[]=$row;
    }
    $this->result->free();
    return $arr;
  }
  function execute_dql_assoc($sql){
    //執(zhí)行查詢語句
    $arr=array();
    $this->result=$this->mysqli->query($sql) or die ($this->mysql->connect_error);
    //將數(shù)據(jù)轉(zhuǎn)存到$arr數(shù)組中
    while($row=mysqli_fetch_array($this->result,MYSQLI_ASSOC)){
      $arr[]=$row;
    }
    $this->result->free();
    return $arr;
  }
  //查詢某表中的記錄數(shù)
  function execute_dql_counts($table,$id="*"){
    $this->sql="select count($id) from $table";
    $this->result=$this->mysqli->query($this->sql);
    $row=mysqli_fetch_all($this->result);
    $this->result->free();
    return $row[0][0];
  }
  function execute_dml($sql){
    //執(zhí)行正刪改
    $this->result=$this->mysqli->query($sql);
    if(!$this->result){
      return -1;//執(zhí)行正刪改失敗
    }else{
      if($this->mysqli->affected_rows>0){
        return 1;//執(zhí)行正刪改成功,影響行數(shù)
      }else{
        return 0;//執(zhí)行正刪改成功,但沒有影響行數(shù)
      }
    }
  }
}