banco.php

<< Click to Display Table of Contents >>

Navigation:  Outros > CRUD simples com Bootstrap >

banco.php

Previous pageReturn to chapter overviewNext page

<?php
 
class Banco
{
    private static $dbNome = 'crud';
    private static $dbHost = 'localhost';
    private static $dbUsuario = 'root';
    private static $dbSenha = '123456';
    
    private static $cont = null;
    
    public function __construct() 
    {
        die('A função Init nao é permitido!');
    }
    
    public static function conectar()
    {
        if(null == self::$cont)
        {
            try
            {
                self::$cont =  new PDO"mysql:host=".self::$dbHost.";"."dbname=".self::$dbNomeself::$dbUsuarioself::$dbSenha); 
            }
            catch(PDOException $exception)
            {
                die($exception->getMessage());
            }
        }
        return self::$cont;
    }
    
    public static function desconectar()
    {
        self::$cont = null;
    }
}