How to optimize the php singleton schema database class to link the database multiple times?

I wrote a mysql database operation class, and then I wrote a model class for each table, and these model inherits the mysql database operation class. My mysql database operation class is in the form of a singleton class. Yesterday, when debugging the code, I tracked the running process and found that each model file would go through the basic work of complete mysql connect selectdb when running. This was completely unexpected to me. The goal I hope to achieve is that operations like connect selectdb only run once, and every other model instantiation only initializes some variables such as tablename, but the code has not been changed for a long time. I hope the gods can help take a look at it. The following code is posted:

partial code of Mysql operation class:

public static function getInstance($db = "master1", array $config = []) {
        $config += Yaf_Registry::get("config")->database["config"][$db]->toArray();

        static $_instance = [];

        empty($config["model"]) && $config["model"] = get_called_class();
        $key = md5(implode(",", $config));
        if (empty($_instance[$key])) {
            $instance = $_instance[$key] = new static($config);
            return $instance;
        }

        return $_instance[$key];
    }

    private function __construct(array &$config) {
        $this->_initConfig($config);
        $this->_initConnection();
        $this->_initTable($config);
        $this->release();
    }

    private function _initConfig(array &$config) {
        !empty($config["host"]) && $this->_config["host"] = $config["host"];
        !empty($config["user"]) && $this->_config["user"] = $config["user"];
        !empty($config["pass"]) && $this->_config["pass"] = $config["pass"];
        !empty($config["data"]) && $this->_config["data"] = $config["data"];
        !empty($config["port"]) && $this->_config["port"] = $config["port"];
        !empty($config["char"]) && $this->_config["char"] = $config["char"];
        !empty($config["pref"]) && $this->_config["pref"] = $config["pref"];
        in_array($config["dbug"], [0, 1]) && $this->_config["dbug"] = $config["dbug"];
        in_array($config["dlog"], [0, 1]) && $this->_config["dlog"] = $config["dlog"];
    }

    private function _initConnection() {
        $this->_conn = mysqli_connect(
            $this->_config["host"],
            $this->_config["user"],
            $this->_config["pass"],
            $this->_config["data"],
            $this->_config["port"]
        ) or die("connect db fail(" . mysqli_connect_errno() . ")" . mysqli_connect_error());

        mysqli_query($this->_conn, "set names " . $this->_config["char"]);
    }

model file code example:

class Db_UserModel extends MySql {......}

the problem is that every model file is instantiated through getInstance, for example:

Db_UserModel::getInstance ()

the number of database links will be generated as many model are instantiated.

how can I change it to what I want it to be? Thank you.

Jun.23,2021

// 
$this->release();  
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd9261-31177.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd9261-31177.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?