<?phpclass Db{ private $dbConfig=[ 'port'=>'3306', 'user'=>' root', 'pass'=>'root', 'charset'=>' utf8', 'dbname'=>'edu', ]; //Einzelfallmodus private static $instance = null; public $num1 = null; private function __construct($params) { //Initialisierungsparameter array_merge($this->dbConfig, $params); //Mit der Datenbank verbinden $this->connect( } private function __clone() { // TODO : Implementieren Sie die Methode __clone(). } öffentliche statische Funktion getInstance($params=[]) { if(!self::$instance exampleof self) { self::$instance = new self($params); Instanz; private Funktion connect() { $dsn="{$this->dbConfig['d b']}:host = {$ this-& gt; dbconfig ['host']}; port = {$ this- & gt; dbconfig ['port']}; ['pass ']); ////Catch (pdoException $ E) {DIE ('Datenbankverbindungsfehler'. $ e- & gt; getMessage ());} public function exec ($ SQL) {$ NUM = $ this- & gt; ; EC ($ sql); if($num>0) if(null !== $this->conn->lastInsertID()) { $this->insertID = $this->conn -> lastInsertID (); fetch(PDO::FETCH_ASSOC); } public function fetchALL($sql) { return $this->conn->query($sql)->fetch(PDO::FETCH_ASSOC);;
pdo对象没有获取成功,调用了一个对象成员方法fetch, 检查连接参数