Skip to content

Instantly share code, notes, and snippets.

@Felipe-Marques
Last active April 16, 2020 21:42
Show Gist options
  • Save Felipe-Marques/aa22596044ca0bbb418d60f318f8d537 to your computer and use it in GitHub Desktop.
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.
<?
//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