zoukankan      html  css  js  c++  java
  • [php]mysqli操作流程

    <?php
    
    class SqlTools{
        private $con;
        private $trans;
        public function __construct($host, $user, $pswd, $db){
            $this->con = new mysqli($host, $user, $pswd, $db);
            if($this->con->connect_error)
                die("CONNECT ERROR:".$this->con->connect_errno.":".$this->con->connect_error."<br/>");
            $this->con->query("set names utf8");
        }
        /*start transaction*/
        public function start_trans(){
            $this->con->autocommit(false);
            $this->trans = true;
        }
        /*rollback*/
        public function rollback(){
            $this->con->rollback();
        }
        /*add, insert, update and so on*/
        public function execute($sql){
            $exec_bool = $this->con->query($sql);
            if($exec_bool)
                die("EXEC ERROR:".$this->con->errno.":".$this->con->error."<br/>");
            return $this->con->affected_rows;
        }
        /*select*/
        public function &execute_query($sql){
            $res = $this->con->query($sql);
            if(!$res)
                die("QUERY ERROR:".$this->con->errno.":".$this->con->error."<br/>");
            return $res;
        }
        /*free resource*/
        public function close(){
            if($this->trans)
                $this->rollback();
            if($this->con)
                $this->con->close();
        }
    }
  • 相关阅读:
    魔法跳舞链 51Nod
    反射
    JDBC---后端服务器与数据库交互的桥梁
    多线程
    IO流
    继承与重写
    java.util包
    多态
    Java.lang包
    异常
  • 原文地址:https://www.cnblogs.com/fantasy01/p/4278741.html
Copyright © 2011-2022 走看看