true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]; try { $this->dbh = new PDO($dsn, $user, $pass, $options); } catch (PDOException $e) { $this->error = $e->getMessage(); // Exception werfen statt sterben! throw new Exception("Datenbank-Verbindungsfehler."); } } public function query($sql) { $this->stmt = $this->dbh->prepare($sql); } public function bind($param, $value, $type = null) { if (is_null($type)) { switch (true) { case is_int($value): $type = PDO::PARAM_INT; break; case is_bool($value): $type = PDO::PARAM_BOOL; break; case is_null($value): $type = PDO::PARAM_NULL; break; default: $type = PDO::PARAM_STR; } } $this->stmt->bindValue($param, $value, $type); } public function execute() { return $this->stmt->execute(); } public function resultSet() { $this->execute(); return $this->stmt->fetchAll(); } public function single() { $this->execute(); return $this->stmt->fetch(); } public function rowCount() { return $this->stmt->rowCount(); } }