zoukankan      html  css  js  c++  java
  • PHP封装数据库连接

    将数据库连接放在类里面,用的时候直接实例化类。

    将数据库地址,用户名,密码做成成员变量

    将数据库连接做成成员方法,通过传入的sql语句返回结果集对象

    class DBDA{
      public $host="localhost";
      public $uid="root";
      public $pwd = "";
      public $dbconnect;

      function Query($sql,$type=1,$dbname="z-stu"){
        $this->dbconnect = new MySQLi($this->host,$this->uid,$this->pwd,$dbname);
        if(!mysqli_connect_error()){
          $result = $this->dbconnect->query($sql);
          if($type == 1){
            $attr = $result->fetch_all();
            return $attr;
          }else{
            return $result;
          }
        }else{
          echo "连接失败";
        }
      }
    }

  • 相关阅读:
    oracle执行.sql文件
    rematch的基本用法
    dva的基本用法
    redux-saga基本用法
    react-redux的基本用法
    redux的基本概念
    mobx基本概念
    centos 编译安装Apache 2.4
    javascript动态添加一组input
    php配置文件语法
  • 原文地址:https://www.cnblogs.com/yongjiapei/p/5585303.html
Copyright © 2011-2022 走看看