php-基於物件導向的MySQL類

來源:互聯網
上載者:User

標籤:


class sqlHelper{       private $conn;       private $host = ‘localhost‘;      private $user = ‘root‘;      private $pwd = ‘root‘;      private $db;     public function __construct($idb){        $this->db = $idb;                    $this->conn = new mysqli($this->host,$this->user,$this->$this->pwd,$this->idb);                    if($this->conn->connect_error){                    $this->error($this->conn->connect_error);       }      $this->conn->query(‘set names  utf8‘);      }  //針對select語句  public function execute_dql($sql){                   $res = $this->conn->query($sql) or $this->error(‘查詢操作失敗‘.$this->conn->error);                   $this->free();                  return $res;   }//針對insert、update、delectpublic function execute_dml($sql){                   $flag =  $this->conn->query($sql) or $this->error($this->conn->error);                   if(!$flag){            return 0 ;//操作失敗        }else{            if($this->conn->afffected_rows > 0){                  return 1;//操作成功            }else{                return 2;//操作失敗沒有行數受到影響            }      }}//針對多行記錄public function fetch_all($sql){         $res = $this->conn->query($sql) or $this->error(‘查詢操作失敗‘.$this->conn->error);                $arr = array();                while($row = $res->fetch_assoc()){          $arr[] = $row;  //及時釋放資源    }                         return $arr;}protected function error($err){                    $log = ‘cur.log‘;                     file_put_contens($log,$err,FILE_APPEND);                     die($err);}}                  

 

 

 

php-基於物件導向的MySQL類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.