-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.php
More file actions
82 lines (72 loc) · 1.97 KB
/
db.php
File metadata and controls
82 lines (72 loc) · 1.97 KB
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
<?php
//*************************************
// PHP Database Class Using MySQL
//*************************************
class database {
private $Host;
private $MySQLUsername;
private $MySQLPassword;
private $Database;
private $Conn;
//Esta es la función principal.
public function connect()
{
require_once(dirname(__FILE__) . '/Settings.php');
$this->Host = $db_server;
$this->MySQLUsername = $db_user;
$this->MySQLPassword = $db_passwd;
$this->Database = $db_name;
$this->Conn = @mysql_connect($this->Host,$this->MySQLUsername,$this->MySQLPassword);
if($this->Conn)
{
mysql_select_db($this->Database) OR die('Could not select DB');
}
else
{
die(mysql_error());
}
unset($this->Host);
unset($this->MySQLUsername);
unset($this->MySQLPassword);
unset($this->Database);
}
// Esta función hace una query a la base de datos actualmente usada
public function Query($sql)
{
$result = mysql_query($sql);
if(!$result)
{
die(mysql_error());
}
return $result;
}
public function Disconnect()
{
mysql_close($this->Conn);
}
// Esto , quita todos los caracteres malos para evitar inyecciones sql , usalo para los campos insertados por usuarios.
public function EscapeString($badstring)
{
if(!get_magic_quotes_gpc())
{
$goodstring = addslashes($badstring);
}
else
{
$goodstring = stripslashes($badstring);
}
$goodstring = mysql_real_escape_string($badstring);
return $goodstring;
}
//Esto coje los resultado de la query y los mete en un array
public function Result_To_Array($result)
{
$result_array = array();
for ($i=0; $row = mysql_fetch_array($result); $i++)
{
$result_array[$i] = $row;
}
return $result_array;
}
}
?>