-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbd.class.php
58 lines (40 loc) · 980 Bytes
/
bd.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class bd{
//host
private $host = 'localhost';
//usuario
private $usuario = 'root';
//senha
private $senha = '';
//banco de dados
private $bd = 'siaf';
private $conn=NULL;
public function conecta_mysql(){
//cria conexao
$this->conn = mysqli_connect($this->host, $this->usuario, $this->senha, $this->bd);
//ajusta charset de comunicação entre aplicação e bd
mysqli_set_charset($this->conn, 'utf8');
//verificar se houve erro de conexão
if(mysqli_connect_errno()){
echo 'Erro ao tentar se conectar com o BD MySQL: ' .mysqli_connect_error();
}
return $this->conn;
}
function __construct()
{
$this->conecta_mysql();
}
public function exec($query,$type,$param){
$stmt=$this->conn->prepare($query);
$stmt->bind_param($type,...$param);
$stmt->execute();
return $stmt->get_result();
}
public function desconecta_mysql(){
mysqli_close($this->conn);
}
function __destruct(){
$this->desconecta_mysql();
}
}
?>