我正在尝试为 MySQLi 编写一个自定义类,但在使用num_rows. 任何人都可以帮忙吗?
class db { 
    private $host = "***";
    private $user = "***";
    private $pass = "***";
    private $database;
    private $connection;
    private $result;
    public $sql;
    function __construct($database) {
        if (!empty($database)) $this->database = $database;
        $this->connection = new mysqli($this->host,$this->user,$this->pass,$this->database);
        return $this->connection;
    }
    public function fetchRowNum($sql) {
        if (!empty($sql)) {
            $this->sql = $sql;
            return $this->connection->query($sql)->num_rows;
        } else {
            throw new Exception("Error fetching row");
        }
    }
}