-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
79 lines (67 loc) · 2.99 KB
/
database.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
<?php
class database {
private $usuario;
private $password;
private $servidor;
private $nomDB;
private $link;
function database() {
$this->usuario = "root";
$this->password = "";
$this->servidor = "localhost";
$this->nomDB = "adminbienes";
$this->link = "";
}
function conectar() {
$this->link = mysqli_connect($this->servidor, $this->usuario, $this->password);
mysqli_select_db($this->link, $this->nomDB);
}
function insertar($fila = array(), $tabla = "") {
$valoresFila = "";
while (list($key, $val) = each($fila)) {
$valoresFila = $valoresFila . " '" . $val . "', ";
}
$valoresFila = substr($valoresFila, 0, -2);
mysqli_query($this->link, " insert into " . $tabla . " values( " . $valoresFila . ");")or die("la consulta fallo (insertar)" . mysqli_errno($this->link));
}
function verificarIdClientes($idCliente, $tabla = "") {
$query = "select id_cliente from " . $tabla . " where id_cliente=" . $idCliente;
$existe = mysqli_query($this->link, $query);
$cantidad = mysqli_num_rows($existe);
return $cantidad;
}
function actualizarActivos($fila = array(), $tabla = "", $id_Activo = "") {
$actualizar = "update " . $tabla . " set tipo_activo='$fila[0]', "
. "categoria='$fila[1]', marca='$fila[2]', modelo='$fila[3]',"
. " descripcion='$fila[4]', notas='$fila[5]' where id_activos='$id_Activo'";
$res = mysqli_query($this->link, $actualizar)or die("la consulta fallo (insertar)" . mysqli_error($this->link));
return $res;
}
function actualizar($fila = array(), $tabla = "", $idCliente = "") {
$actualizar = "update " . $tabla . " set correo='$fila[0]', num_hijos='$fila[1]', ruta='$fila[2]' where id_cliente='$idCliente'";
mysqli_query($this->link, $actualizar) and mysql_info();
}
function insertarActivo($fila = array(), $tabla = "") {
$valoresFila = "";
while (list($key, $val) = each($fila)) {
$valoresFila = $valoresFila . " '" . $val . "', ";
}
$valoresFila = substr($valoresFila, 0, -2);
//quitar en sql_error($link) si no es link + $this-> link
mysqli_query($this->link, " insert into " . $tabla . " values( " . $valoresFila . ");")or die("la consulta fallo(insertarActivo)" . mysqli_error($this->link));
}
function consultarDB($tabla = "", $campo = "", $dato = "", $campoEspeci = "") {
if ($campo == "") {
$query = "select * from " . $tabla;
} else if ($dato == "") {
$query = "select " . $campo . " from " . $tabla;
} else if ($campoEspeci == "") {
$query = "select * from " . $tabla . " where " . $campo . " = " . $dato;
} else {
$query = "select " . $campoEspeci . " from " . $tabla . " where " . $campo . " = " . $dato;
}
$res = mysqli_query($this->link, $query);
return $res;
}
}
?>