Tag:io ar os sp Data on problem cti bs
class db{ private $db _config = './config.php '; private static $_instance; private function __construct () { if (file_exists ($this->db_ Config) { require $this db_config; self::$_instance = new mysqli ($db _host, $db _name, $db _passwd); } else { throw new exception (' Not found database configuration file. '); } } /** * Single Case Method  : Static methods for user access to instances * * @return void */ public function getinstance () { if (self::$_instance == null) { self::$_instance = new self; } file_put_contents (' 2.txt ', var_export (self::$_instance,true), file_append); return self::$_instance; } /** * prevent objects from being cloned * * @return void */ private function __clone () { trigger_error (' clone is not allow! ', e_user_error); }}
Try to write a database connection in a singleton mode, in the execution, found through the getinstance () method obtained only $db _config, and did not get the instantiated Mysqli object, want to ask, where is the problem?
Where else can it be optimized?
PHP Singleton mode for database connection