Advertisement
Guest User

Untitled

a guest
May 6th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2. /*
  3. * @author Jota Vicente <jotavrj at gmail dot com>
  4. *
  5. */
  6. class Connection extends PDO { #classe de conexão com o BD
  7.     private $dsn = 'mysql:dbname=testes;host=127.0.0.1';
  8.     private $user = 'root';
  9.     private $password = '';
  10.     public $handle = null;
  11.  
  12.     function __construct( ) {
  13.         try {
  14.             if ( $this->handle === null ) {
  15.                 $dbh = parent::__construct( $this->dsn , $this->user , $this->password );
  16.                 $this->handle = $dbh;
  17.                 return $this->handle;
  18.             }
  19.         }
  20.         catch ( PDOException $e ) {
  21.             echo 'Connection failed: ' . $e->getMessage( );
  22.             return false;
  23.         }
  24.     }
  25.  
  26.     function __destruct( ) {
  27.         $this->handle = NULL;
  28.     }
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement