note 125288 deleted from ref.pdo-mysql.connection by cmb
| From: | cmb@php.net | Date: | Wed, 19 Aug 2020 14:58:59 +0000 |
| Subject: | note 125288 deleted from ref.pdo-mysql.connection by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214997@lists.php.net to get a copy of this message | ||
Note Submitter: Thyago Frana
----
<?php
Class Conexao {
private $host = "127.0.0.1"; // boa pratica começar a usar ip no lugar de
localhost
private $user = "root";
private $pass = "";
private $database = "sistema_login";
public function conectar() {
try{
$conexao = new
PDO("mysql:host=$this->host;dbname=$this->database;charset=utf8", $this->user,
$this->pass);
$conexao->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $erro) {
echo "Erro ao tentar se conectar com o Banco de Dados:
{$erro->getMessage()}"; //{$erro->getMessage()} esta concatenando
$conexao = null;
}
return $conexao;
}
};
?>