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
136
137
138
139
140
141
142
143
144
145
<?php
/*
**********************************************************************
Por: Jose Mar?Rodr?ez Valls
Para: http://php.elcurriculum.com
ver 1.0 2005 Todos los derechos quedan reservados.
**********************************************************************
*/
class clBD {
function OBTPost($datos, $modo = true) {
$ret = array();
if ($modo) {
$c = split(',', $datos);
foreach ($_POST as $k => $v) {
if (array_search($k, $c) === false) {
$ret[$k] = $v;
}
}
} else {
$c = split(',', $datos);
foreach ($c as $k => $v) {
$ret[$v] = $_POST[$v];
}
}
return $ret;
}
function OBTGet($datos, $modo = true) {
$ret = array();
if ($modo) {
$c = split(',', $datos);
foreach ($_GET as $k => $v) {
if (array_search($k, $c) === false) {
$ret[$k] = $v;
}
}
} else {
$c = split(',', $datos);
foreach ($c as $k => $v) {
$ret[$v] = $_GET[$v];
}
}
return $ret;
}
function OBTSesion($datos, $modo = true) {
$ret = array();
if ($modo) {
$c = split(',', $datos);
foreach ($_SESSION as $k => $v) {
if (array_search($k, $c) === false) {
$ret[$k] = $v;
}
}
} else {
$c = split(',', $datos);
foreach ($c as $k => $v) {
$ret[$v] = $_SESSION[$v];
}
}
return $ret;
}
function SQLInsert($tabla, $contenido) {
$sSQL = "insert into `$tabla` (`id_$tabla`";
$sSUF = '';
foreach ($contenido as $k => $v) {
$sSQL .= ',`' . $k . '`';
$sSUF .= ',\'' . $v . '\'';
}
$sSQL .= ") values (LAST_INSERT_ID()" . $sSUF . ')';
return $sSQL;
}
function SQLUpdate($tabla, $contenido, $id) {
$sSQL = "update `$tabla` set";
foreach ($contenido as $k => $v) {
$sSQL .= ' ' . $k . ' = \'' . $v . '\',';
}
$sSQL = substr($sSQL, 0 , strlen($sSQL) -1);
$sSQL .= " where id_$tabla = '$id'";
return $sSQL;
}
function SQLDelete($tabla, $id) {
return "delete from `$tabla` where id_$tabla = '$id'";
}
}
class clMySQL extends clBD {
var $abierto;
var $con;
var $host;
var $bd;
var $usr;
var $psr;
function clMySQL($host, $bd, $usr, $psr) {
$this->abierto = false;
$this->host = $host;
$this->bd = $bd;
$this->usr = $usr;
$this->psr = $psr;
}
function OpenMySQL() {
if (!$this->abierto) $this->con = mysql_connect($this->host, $this->usr, $this->psr);
mysql_select_db($this->bd, $this->con);
$this->abierto = true;
}
function BDConexion($sql) {
if (!$this->abierto) $this->OpenMySQL();
return mysql_query($sql, $this->con);
}
function BDInsert($tabla, $contenido) {
if (!$this->abierto) $this->OpenMySQL();
if (mysql_query($this->SQLInsert($tabla, $contenido), $this->con)) {
return mysql_insert_id($this->con);
} else {
return -1;
}
}
function BDUpdate($tabla, $contenido, $id) {
if (!$this->abierto) $this->OpenMySQL();
return $this->BDConexion($this->SQLUpdate($tabla, $contenido, $id));
}
function BDDelete($tabla, $id) {
if (!$this->abierto) $this->OpenMySQL();
return $this->BDConexion($this->SQLDelete($tabla, $id));
}
function CloseMySQL() {
if ($this->abierto) mysql_close($this->con);
$this->abierto = false;
}
}
?>