Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DatabaseTest
- {
- const DSN = DSN_DB;
- const USER = USER_DB;
- const PASSWORD = PASSWORD_DB;
- const OPTIONS = OPTIONS_PDO;
- protected $connection_status;
- protected $error_message;
- protected $db_connect;
- protected function connect()
- {
- try {
- $this->db_connect = new PDO(self::DSN, self::USER, self::PASSWORD, self::OPTIONS );
- //ejecutamos la conexion
- $this->connection_status = true; //asignamos true al atributo
- $this->error_message = "";
- } catch (PDOException $e) { //entramos si se encuentra un error o exeption
- $this->connection_status = false; //asignamos el valor a false
- $this->error_message = "error en: ".$e->getMessage(); // asignamos el mensaje del error al atributo
- }
- }
- protected function getConnectionStatus()
- {//metodo que retorna el estatus de la conexion, lo implementamos en cada metodo que opera con la conexion con la base de datos (INSERT, SELECT, UPDATE, DELETE)
- return $this->connection_status;
- }
- protected function getErrorMessage()
- { //metodo que nos devuelve el mensaje de error si no llega a darse la conexion
- return $this->error_message;
- }
- protected function disconnect()
- {//metodo implementado para simular el cierre de conexion
- $this->connection_status = false;
- $this->db_connect = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement