Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once '../initProjeto.php';
- class Conexao{
- private $host = DB_HOST;
- private $database = DB_NAME;
- private $gerenciador = DB_TYPE;
- private $user = DB_USER;
- private $password = DB_PASSWORD;
- public static $instance;
- public $conex = NULL;
- public function __construct(){
- try {
- $strConexao = $this->gerenciador.':dbname='.$this->database.';host='.$this->host.';';
- $this->conex = new PDO($strConexao, $this->user, $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_PERSISTENT => true) );
- } catch (PDOException $e) {
- die('Erro na conexão com o banco de dados: ' . $e->getMessage());
- }
- }
- public function __destruct(){
- $this->conex = null;
- }
- public static function getConnection(){
- if(!self::$instance) {
- self::$instance = new conexao();
- }
- return self::$instance->conex;
- }
- public function closeConex () {
- $this->conex = NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement