-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.class.inc.php
126 lines (124 loc) · 3.31 KB
/
db.class.inc.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
<?php
class comDb {
var $connection_exists = false;
var $connection_handler = false;
var $error = false;
var $errorMessage = "";
var $queryCount = 0;
var $queries = "";
var $debugQueries = true;
function comDb($dbname = "genesis", $host = "localhost", $user = "root", $password = "")
{
$this -> connection_link = mysql_connect ($host, $user, $password) or die('Konnte MySQL-Server nicht erreichen');
mysql_select_db($dbname) or die('Konnte Datenbank "' . $dbname . '" nicht auswählen');
$this -> connection_exists = true;
}
function query($sql, $echo = false)
{
if ($echo) {
echo '<div style="font-size:16pt;">';
echo nl2br(htmlentities($sql));
echo '</div>';
}
$tmpTime = 0;
if ($this -> connection_exists) {
$tmpTime = microtime();
$this -> connection_handler = mysql_query($sql);
$tmpTime = microtime() - $tmpTime;
if (!$this -> connection_handler) {
$this -> error = true;
$this -> errorMessage .= "Fehlerhafter Query: " . $sql . "<br />\nMySQL-Fehlermeldung: " . mysql_error();
die($this -> errorMessage);
}
} else {
die('Es wurde noch keine Verbindung hergestellt.');
}
if ($this -> debugQueries) {
++$this -> queryCount;
$this -> queries .= $this -> queryCount;
$this -> queries .= ": " . $sql . "<br />\n";
$this -> queries .= "<br />Time taken: " . $tmpTime . "s<br />\n";
}
}
function get_1d_array()
{
if (!$this -> connection_handler) {
$this -> error = true;
$this -> errorMessage .= "Es wurde kein Query abgeschickt";
return false;
}
return mysql_fetch_assoc($this -> connection_handler);
}
function get_2d_array()
{
if (!$this -> connection_handler) {
$this -> error = true;
$this -> errorMessage .= "Es wurde kein Query abgeschickt";
return false;
}
$tmp_super = array();
$tmp_row = array();
while ($tmp_row = mysql_fetch_assoc($this -> connection_handler)) {
$tmp_super[] = $tmp_row;
}
return $tmp_super;
}
function get_affected_rows()
{
if (!$this -> connection_handler) {
$this -> error = true;
$this -> errorMessage .= "Es wurde kein Query abgeschickt";
return false;
}
return mysql_affected_rows($this -> connection_link);
}
function get_num_rows()
{
if (!$this -> connection_handler) {
$this -> error = true;
$this -> errorMessage .= "Es wurde kein Query abgeschickt";
return false;
}
return mysql_num_rows($this -> connection_handler);
}
function get_inserted_id()
{
if (!$this -> connection_handler) {
$this -> error = true;
$this -> errorMessage .= "Es wurde kein Query abgeschickt";
return false;
}
return mysql_insert_id();
}
function escapeNumberForQuery($number)
{
if (is_numeric($number)) {
return $number;
} else {
return 0;
}
}
function escapeIdForQuery($id)
{
return intval($id);
}
function escapeStringForQuery($string)
{
return mysql_real_escape_string(strip_tags($string));
}
function escapeHtmlForQuery($string)
{
return mysql_real_escape_string($string);
}
function destroy()
{
if ($this -> debugQueries) {
echo '<div style="text-align:left;">', nl2br($this -> queries), '</div>', "<br />";
echo '<br /><span style="font-size:12pt;">Anzahl der Queries: ' . $this -> queryCount . '</span><br />';
}
mysql_close($this -> connection_link);
$this -> connection_link = null;
$this -> connection_exists = false;
}
}
?>