db = new PDO($dsn, $envs['db']['id'], $envs['db']['passwd']); $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } // abstract public function getTable(); final public function getDB() { return $this->_db; } final public function setDebug($debug) { $this->_debug = $debug; } final public function getDebug() { return $this->_debug; } final public function setMode($mode) { $this->_mode = $mode; } final public function getMode() { return $this->_mode; } final public function execute($sql) { $stmt = $this->db->prepare($sql); $stmt->execute(); return $stmt; } final protected function getRow($sql) { $stmt = $this->execute($sql); return $stmt->fetch($this->getMode()); } final protected function getRows($sql, $mode = PDO::FETCH_OBJ) { $stmt = $this->execute($sql); return $stmt->fetchAll($this->getMode()); } final public function getData($wheres = array(), $column = "*") { $sql = sprintf("SELECT %s FROM %s %s", $column, $this->getTable(), count($wheres) ? "WHERE " . implode("AND", $wheres) : ""); echo $sql; return $this->getRow($sql); } final public function getDatas(array $wheres = array(), $column = "*") { $sql = sprintf("SELECT %s FROM %s %s", $column, $this->getTable(), count($wheres) ? "WHERE " . implode("AND", $wheres) : ""); echo $sql; return $this->getRows($sql); } } //Class