解决方案 »

  1.   

    你在构造函数中
     function __construct() {
        // 连接数据库
        $this->conn = mysqli_connect("localhost", "root", "pass", "2shou"); 
        mysqli_query($this->conn, "SET NAMES gbk");
     }
    所以 $this->conn 是资源
    但你在其他方法中却用 $results = $this->conn->query($sql); 进行访问
    那么 $this->conn 什么时候又变成对象了呀?
      

  2.   

    所以构造函数应写作function __construct() {
      $this->conn = new mysqli("localhost", "root", "pass", "2shou");
      $this->conn->set_charset('gbk');
    }