SHARE
TWEET

Untitled

a guest Aug 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Conexao {
  4.     private $host = null;
  5.     private $banco = null;
  6.     private $usuario = null;
  7.     private $senha = null;
  8.     public $conn = null;
  9.     public $sql = null;
  10.     public $result = null;
  11.  
  12.     public function __construct($host, $banco, $usuario, $senha) {
  13.         $this->host = $host;
  14.         $this->banco = $banco;
  15.         $this->usuario = $usuario;
  16.         $this->senha = $senha;
  17.     }
  18.  
  19.     public function __get($atributo) {
  20.         return $this->atributo;
  21.     }
  22.  
  23.     public function __set($atributo, $valor) {
  24.         $this->$atributo = $valor;
  25.     }
  26.  
  27.     public function conexaoComBanco() {
  28.  
  29.         try {
  30.             $this->conn = new PDO("mysql:host=$this->host; dbname=$this->banco, '$this->usuario', '$this->senha'");
  31.             $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  32.             echo 'Conex√£o realizada com sucesso!';
  33.  
  34.         } catch(PDOException $e) {
  35.             echo $e->getMessage();
  36.         }
  37.     }
  38. }
  39.  
  40. $conexao = new Conexao('localhost', 'bancoteste', 'wilder', '12345');
  41.  
  42. $conexao->conexaoComBanco();
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