zoukankan      html  css  js  c++  java
  • php-基于面向对象的MySQL类

    
    
    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、delect
    
    public 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);
    }
    }
                      
    
    
    
     
  • 相关阅读:
    cvLoadImage cvCreateImage函数使用方法
    CString 的FindOneOf
    FTP与SFTP的区别
    如何在Linux环境下编译lib 库
    CString 和 string之间的转换
    Cstring getlength
    CString类常用方法----Left(),Mid(),Right()……
    LPCTSTR
    明白fopen的参数r+,w+以及a+
    libsvm -c http://www.ilovematlab.cn/thread-89155-1-1.html
  • 原文地址:https://www.cnblogs.com/YangJieCheng/p/5689324.html
Copyright © 2011-2022 走看看