<?phpclass Db{ private $dbConfig=[ '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); //Connection The database $ this-& gt; connect ();} Private function __clone () {// todo: Implement __Clone () Method.} Public Static Function GetInstance ! Self :: $ Instance Instanceof Self ){ self::$instance = new self($params); } return self::$instance; } private function connect() { try { $dsn="{$this->dbConfig['d b']}: host={$this->dbConfig['host']}; port={$this->dbConfig['port']};dbname={$this->dbConfig['dbname']}; charset= {$this->dbConfig['charset']}"; dbConfig['pass']); //// //// $this->conn->query("SET NAMES {$this->dbConfig['charset']}");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);; }}
灭绝师太2021-01-12 09:08:06
The pdo object was not obtained successfully, and an object member method fetch was called to check the connection parameters.