SHARE
TWEET

Untitled

a guest Dec 23rd, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $link = mysqli_connect("0.0.0.0", "teste", "teste", "teste");
  2. mysqli_set_charset($link, "utf8");
  3.  
  4. if (mysqli_connect_errno()) {
  5.     printf("<br> Nao foi possivel conectar. Erro: %sn", mysqli_connect_error());
  6.     exit();
  7. }
  8.  
  9. $database_host = "0.0.0.0";
  10. $database_user = "teste";
  11. $database_password = "teste";
  12. $database_db = "teste";
  13.  
  14. $conexao = new mysqli($database_host, $database_user, $database_password, $database_db);
  15. mysqli_set_charset($conexao, "utf8");
  16. if ($conexao->connect_error) {
  17.     die("A conexão falhou!");
  18. }
  19. date_default_timezone_set("America/Sao_Paulo");
  20.    
  21. class ConexaoBanco extends PDO {
  22.  
  23.     private static $instancia = null;
  24.  
  25.     public function ConexaoBanco($dsn, $usuario, $senha) {
  26.         //Construtor da classe pai PDO
  27.         parent::__construct($dsn, $usuario, $senha);
  28.     }
  29.  
  30.     public static function getInstancia() {
  31.         if (!isset(self::$instancia)) {
  32.             try {
  33.                 // Cria e retorna uma nova conexão
  34.                 self::$instancia = new ConexaoBanco("mysql:dbname=teste;host=0.0.0.0", "teste", "teste");
  35.             } catch (Exception $e) {
  36.                 echo 'Erro ao conectar o banco de dados!';
  37.                 exit();
  38.             }
  39.         }
  40.         return self::$instancia;
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top