Last active
April 16, 2020 21:42
-
-
Save Felipe-Marques/aa22596044ca0bbb418d60f318f8d537 to your computer and use it in GitHub Desktop.
Conexão com Banco de Dados utilizando programação Orientada a Objetos e PDO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//Conexão com Banco de Dados. | |
class Conexao{ | |
private $host = 'localhost'; | |
private $dbname = 'db_controle'; | |
private $user = 'root'; | |
private $password = ''; | |
public function Conectar(){ | |
try{ | |
//Somente aspas duplas. | |
$conexao = new PDO( | |
"mysql:host=$this->host;dbname=$this->dbname", | |
"$this->user", | |
"$this->password" | |
); | |
return $conexao; | |
}catch(PDOException $err){ | |
echo 'ERRO: ' .$err->getCode(). ' - DESCRIÇÃO: ' .$err->getMessage(); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment