【发布时间】:2015-03-28 19:48:55
【问题描述】:
我是 OOP 的新手。我有类数据库
class Database{
private $host;
private $user;
private $pass;
private $db;
public $mysqli;
function db_connect(){
$this->host = 'localhost';
$this->user = 'root';
$this->pass = '';
$this->db = 'db';
$this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->db);
return $this->mysqli;
}
在类数据库中我有函数 db_num
function db_num($sql){
$num = mysqli_num_rows(mysqli_query($this->mysqli,"{$sql}"));
return $num;
}
但是当我在 con 参数 $this->mysqli 中使用时它无法连接到数据库
【问题讨论】: