<?phpclass Db{ private $dbConfig=[ 'port'=>'3306', 'user'=> ;'root , ]; //Einzelfallmodus private static $instance = null; public $insertID = null ; public $num1 = null; ///Datenbankverbindung private $conn = private function __construct($params) { //Initialisierungsparameter array_merge($this->dbConfig, $params); this->connect(); } private function __clone() { // TODO: Implementiere die __clone()-Methode } public static function getInstance($params=[]) { if(!self::$instance exampleof self){ self::$instance = new self($params); return self::$instance; private function connect() { try { $dsn="{$this->dbConfig['db']}:host= {$ this->dbConfig['host']}; this->dbConfig['charset']}"; 'bestanden']);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, 检查连接参数.