-
Notifications
You must be signed in to change notification settings - Fork 0
/
pregunta.model.php
135 lines (118 loc) · 2.72 KB
/
pregunta.model.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
class PreguntaModel
{
private $pdo;
public function __CONSTRUCT()
{
try
{
$this->pdo = new PDO('mysql:host=localhost;dbname=db_gamificame', 'root', '');
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
die($e->getMessage());
}
}
public function Listar()
{
try
{
$result = array();
$stm = $this->pdo->prepare("SELECT * FROM tb_pregunta");
$stm->execute();
foreach($stm->fetchAll(PDO::FETCH_OBJ) as $r)
{
$preg = new Pregunta();
$preg->__SET('intidpregunta', $r->intidpregunta);
$preg->__SET('intidtarea', $r->intidtarea);
$preg->__SET('nvchpregunta', $r->nvchpregunta);
$preg->__SET('nvchdescripcion', $r->nvchdescripcion);
$preg->__SET('chrhabilitado', $r->chrhabilitado);
$result[] = $preg;
}
return $result;
}
catch(Exception $e)
{
die($e->getMessage());
}
}
public function Obtener($intidpregunta)
{
try
{
$stm = $this->pdo
->prepare("SELECT * FROM tb_pregunta WHERE intidpregunta = ?");
$stm->execute(array($intidpregunta));
$r = $stm->fetch(PDO::FETCH_OBJ);
$preg = new Pregunta();
$preg->__SET('intidpregunta', $r->intidpregunta);
$preg->__SET('intidtarea', $r->intidtarea);
$preg->__SET('nvchpregunta', $r->nvchpregunta);
$preg->__SET('nvchdescripcion', $r->nvchdescripcion);
$preg->__SET('chrhabilitado', $r->chrhabilitado);
return $preg;
} catch (Exception $e)
{
die($e->getMessage());
}
}
public function Eliminar($intidpregunta)
{
try
{
$stm = $this->pdo
->prepare("DELETE FROM tb_pregunta WHERE intidpregunta = ?");
$stm->execute(array($intidpregunta));
} catch (Exception $e)
{
die($e->getMessage());
}
}
public function Actualizar(Pregunta $data)
{
try
{
$sql = "UPDATE tb_pregunta SET
intidtarea = ?,
nvchpregunta = ?,
nvchdescripcion = ?,
chrhabilitado = ?
WHERE intidpregunta = ?";
$this->pdo->prepare($sql)
->execute(
array(
$data->__GET('intidtarea'),
$data->__GET('nvchpregunta'),
$data->__GET('nvchdescripcion'),
$data->__GET('chrhabilitado'),
$data->__GET('intidpregunta')
)
);
} catch (Exception $e)
{
die($e->getMessage());
}
}
public function Registrar(Pregunta $data)
{
try
{
$sql = "INSERT INTO tb_pregunta (intidtarea,nvchpregunta,nvchdescripcion,chrhabilitado)
VALUES (?, ?, ?, ?)";
$this->pdo->prepare($sql)
->execute(
array(
$data->__GET('intidtarea'),
$data->__GET('nvchpregunta'),
$data->__GET('nvchdescripcion'),
$data->__GET('chrhabilitado')
)
);
} catch (Exception $e)
{
die($e->getMessage());
}
}
}