Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class ClsABSDataBase {
- private static $host = "localhost";
- private static $user = "root";
- private static $pass = "";
- protected $db = "nombre_basededatos";
- private $conex;
- protected $query;
- protected $data = array();
- protected $result = array();
- abstract protected function get($query, $data);
- abstract protected function set($query, $data);
- abstract protected function edit($query, $data);
- private function conDB($db = '') {
- try {
- $this->db = ($db != '') ? $db : $this->db;
- $this->conex = new PDO("mysql:host=" . self::$host . ";dbname=$this->db", self::$user, self::$pass);
- $this->conex->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $ex) {
- die("Error SQL [" . $ex->getCode() . "] " . $ex->getMessage());
- }
- }
- private function desconDB() {
- try {
- $this->conex = null;
- } catch (PDOException $ex) {
- die("Error SQL [" . $ex->getCode() . "] " . $ex->getMessage());
- }
- }
- protected function getResult() {
- try {
- $this->conDB();
- $eSql = $this->conex->prepare($this->query);
- $eSql->execute($this->data);
- $this->result = $eSql->fetchAll(PDO::FETCH_ASSOC);
- $this->desconDB();
- } catch (PDOException $ex) {
- die("Error SQL [" . $ex->getCode() . "] " . $ex->getMessage());
- }
- }
- protected function query() {
- try {
- $this->conDB();
- $eSql = $this->conex->prepare($this->query);
- $eSql->execute();
- $this->desconDB();
- } catch (PDOException $ex) {
- die(md_err($ex->getCode(), $ex->getMessage(), "Error SQL"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment