Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Conexao {
- private $host = null;
- private $banco = null;
- private $usuario = null;
- private $senha = null;
- public $conn = null;
- public $sql = null;
- public $result = null;
- public function __construct($host, $banco, $usuario, $senha) {
- $this->host = $host;
- $this->banco = $banco;
- $this->usuario = $usuario;
- $this->senha = $senha;
- }
- public function __get($atributo) {
- return $this->atributo;
- }
- public function __set($atributo, $valor) {
- $this->$atributo = $valor;
- }
- public function conexaoComBanco() {
- try {
- $this->conn = new PDO("mysql:host=$this->host; dbname=$this->banco, '$this->usuario', '$this->senha'");
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo 'Conexão realizada com sucesso!';
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- }
- }
- $conexao = new Conexao('localhost', 'bancoteste', 'wilder', '12345');
- $conexao->conexaoComBanco();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement