将 mysqli 传递给 class 不显示结果

Passing mysqli to class doesn't show results

我在将 mysqli 传递给我的 class 时遇到问题。当它传递给非 class 时它工作正常。 我尝试在这里使用依赖注入,但由于某种原因,它在打印时不会显示结果,它只是一个空白页。

这是我的 connect.php

   <?php
$db = new mysqli('localhost', 'root', '', 'audiologiska_kliniken');

if($db->connect_errno > 0){
    die('Ett fel inträffade [' . $db->connect_error . ']');
}

我的测试class:

   <?php
    //error_reporting(0);
    include '../include/connect.php';


    class test
    {
        private $mysqli;

        function __construct(mysqli $db)
        {
            $this->mysqli = $db;
            $this->testing();
        }
        function testing()
        {
            $result = $this->mysqli->query("Select * from person");
                print_r($result);
        }
    }

您不是为了使用它而实例化测试

include '../include/connect.php';

class test
{
    private $mysqli;

    function __construct(mysqli $db)
    {
        $this->mysqli = $db;
        $this->testing();
    }
    function testing()
    {
        $result = $this->mysqli->query("Select * from person");
            print_r($result);
    }
}

new test($db);