-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.agenda.php
86 lines (52 loc) · 1.89 KB
/
class.agenda.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
<?php
include 'config/class.conexion.php';
class Agenda{
protected $nombre;
protected $domicilio;
protected $telefono;
protected $comentrios;
protected $id;
public function __construct($nom, $dom, $tel, $com, $id=''){
$db = new Conexion();
$this->nombre = $db->real_escape_string($nom);
$this->domicilio = $db->real_escape_string($dom);
$this->telefono = $db->real_escape_string($tel);
$this->comentarios = $db->real_escape_string($com);
$this->id = $db->real_escape_string($id);
}
static function ningunDato(){
return new self('', '', '', '', '');
}
static function soloId($id){
return new self('', '', '', '', $id);
}
public function insert(){
$db = new Conexion();
$sql = "INSERT INTO `contactos`(`nombre`, `domicilio`, `telefono`, `comentarios`)
VALUES ('$this->nombre', '$this->domicilio', '$this->telefono', '$this->comentarios')";
$db->query($sql) ? header("location: index.php?res=insertado") : header("location: index.php?res=error");
}
public function update(){
$db = new Conexion();
$sql = "UPDATE `contactos` SET `nombre`= '$this->nombre',`domicilio`= '$this->domicilio',`telefono`='$this->telefono',`comentarios`= '$this->comentarios' WHERE `id` = $this->id";
$db->query($sql) ? header("location: index.php?res=editado") : header("location: index.php?res=error");
}
public function delete(){
$db = new Conexion();
$sql = "DELETE FROM `contactos` WHERE `id`=$this->id";
$db->query($sql) ? header("location: index.php?res=eliminado") : header("location: index.php?res=error");
}
public function selectId(){
$db = new Conexion();
$sql="SELECT * FROM `contactos`WHERE `id` = $this->id";
$result = $db->query($sql);
return $result;
}
public function select(){
$db = new Conexion();
$sql="SELECT * FROM `contactos`";
$result = $db->query($sql);
return $result;
}
}
?>