<?php
class FZL
{
   public $host="localhost";
   public $uid ="root";
   public $pwd ="15864477048";
   public $dbname ="mydb";    
   
   //成员方法  是用来执行sql语句的方法
   public function Query($sql,$type=1)
   {
          $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
          $r = $db->query($sql);
          
          if($type==1)
          {
              return $r->fetch_all();  
          }
          else
          {
              return $r;  
          }
   }
}

能不能把访问数据库做成一个类

调方法

把4个参数写成:成员变量

造连接对象访问数据库

接着写成员方法,来执行SQL语句的方法

需要用户传入参数

括号里两个 第一个SQL语句,可以执行SQL语句并且返回想要的结果

               第二个参数用来判断这条SQL语句是查询还是增删改

要实现的功能

1.造连接对象

2.执行

3.判断

以上有助于后期的修改程序

相关文章:

  • 2021-05-23
  • 2021-07-05
  • 2021-09-28
  • 2021-05-18
  • 2021-11-22
  • 2021-11-04
  • 2021-12-17
猜你喜欢
  • 2021-06-04
  • 2021-10-20
  • 2021-05-09
  • 2021-07-03
  • 2021-09-28
  • 2021-11-16
相关资源
相似解决方案