<?phpclass Db{ private $dbConfig=[ 'db'=>'mysql', 'host'=>'localhost', 'port'=>'3306', 'user'=> ;'root', 'pass'=>'root', 'charset'=>'utf8', 'dbname'=>''edu', ]; //Single case mode private static $instance = null; public $insertID = null; public $num1 = null; ///Database connection private $conn = null; private function __construct($params) { //Initialization parameters array_merge($this->dbConfig, $params); // Connect to the database $this->connect(); } private function __clone() { // TODO: Implement __clone() method. } public static function getInstance($params=[]) { if(!self::$instance instanceof self){ self::$instance = new self($params); } return self::$instance; } private function connect() { try { $dsn="{$this->dbConfig[' db']} charset ={$this->dbConfig['charset']}"; ;dbConfig['pass']); CATCH (pdoexception $ E) {DIE ('database connection failed'. $ E-& GT; getMessage ());} public function exec ($ SQL) {$ NUM = $ this- & gt; conn-& gt; exce; C ($ sql); if($num>0) if(null !== $this->conn->lastInsertID()) { $this->insertID = $this->conn- >lastInsertID() ; $this->num1= $num; print 'Operation failed '.$error[0].':'.$error[1].':'.$error[2]; , fetch($sql) . $sql)->fetch(PDO::FETCH_ASSOC); } public function fetchALl($sql) { return $this->conn->query($sql)->fetch(PDO::FETCH_ASSOC);; }}
The pdo object was not obtained successfully, and an object member method fetch was called to check the connection parameters