-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprueba.php
105 lines (91 loc) · 2.42 KB
/
prueba.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
class Factura
{
private $pdo;
public function __CONSTRUCT()
{
try
{
$this->pdo = new PDO('mysql:host=localhost;dbname=db', '', '');
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die($e->getMessage());
}
}
public function Consulta()
{
try
{
$result = array();
$stm = $this->pdo->prepare("SELECT * FROM factura");
$stm->execute();
foreach($stm->fetchAll(PDO::FETCH_OBJ) as $r)
{
$alm = new factura();
$alm->__SET('id', $r->id);
$alm->__SET('FechaEmision', $r->FechaEmision);
$alm->__SET('FechaVencimiento', $r->FechaVencimiento);
$result[] = $alm;
}
return $result;
}
catch(Exception $e)
{
die($e->getMessage());
}
}
public function Eliminar($id)
{
try
{
$stm = $this->pdo
->prepare("DELETE FROM factura WHERE id = ?");
$stm->execute(array($id));
} catch (Exception $e)
{
die($e->getMessage());
}
}
public function Actualizar(Factura $data)
{
try
{
$sql = "UPDATE factura SET
FechaEmision = ?,
FechaVencimiento = ?,
Precio =?
WHERE id = ?";
$this->pdo->prepare($sql)
->execute(
array(
$data->__GET('FechaEmision'),
$data->__GET('FechaVencimiento'),
$data->__GET('Precio')
)
);
} catch (Exception $e)
{
die($e->getMessage());
}
}
public function Altas(Factura $data)
{
try
{
$sql = "INSERT INTO detalle_factura (FechaEmision,FechaVencimiento)
VALUES (?, ?)";
$this->pdo->prepare($sql)
->execute(
array(
$data->__GET('FechaEmision'),
$data->__GET('FechaVencimiento'),
)
);
} catch (Exception $e)
{
die($e->getMessage());
}
}
}