-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conexao.php
41 lines (34 loc) · 1.15 KB
/
Conexao.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
<?php
class Conexao{
private $conn;
public function __construct(){
$this->conn = new PDO('mysql:host=localhost;dbname=teste', 'root', '');
try {
$conn = new PDO('mysql:host=localhost;dbname=teste', 'root', '');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
}
public function executa($sql){//inserir
//$this->conn->beginTransaction();
$stmt=$this->conn->prepare($sql);
$stmt->execute();
//$this->conn->commit();
return $this->conn->lastInsertId();
}
public function consultar($sql){
$sql = "select * from agenda";
$stmt=$this->conn->prepare($sql);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}// AJUSTAR ESSE MÉTODO PARA RECEBER AS INFORMAÇÕES
// public function executaprepare($sql,$parametros){
// $stmt=$this->conn->prepare($sql);
// $stmt->execute($parametros);
// // $data=$stmt->fetch(PDO::FETCH_OBJ);
//
// return $data;
// }
}
?>