Subversion Repositories personal-webbase

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
<?php
2
 
3
if (!defined('WBLEGAL')) die('Kann nicht ohne Personal WebBase ausgef&uuml;hrt werden.');
4
 
5
function db_connect()
6
{
7
        global $WBConfig;
8
        global $wb_selc;
9
        global $wb_conn;
10
 
11
        if ($WBConfig->getMySQLPort() != '')
12
                $zus = ':'.$WBConfig->getMySQLPort();
13
        else
14
                $zus = '';
15
 
16
        if ($WBConfig->getMySQLUseMySQLI()) {
17
                $wb_conn = @mysqli_connect($WBConfig->getMySQLServer().$zus, $WBConfig->getMySQLUsername(), $WBConfig->getMySQLPassword());
18
                $wb_selc = @mysqli_select_db($WBConfig->getMySQLDatabase(), $wb_conn);
19
        } else {
20
                $wb_conn = @mysql_connect($WBConfig->getMySQLServer().$zus, $WBConfig->getMySQLUsername(), $WBConfig->getMySQLPassword());
21
                $wb_selc = @mysql_select_db($WBConfig->getMySQLDatabase(), $wb_conn);
22
        }
23
 
24
        if ((!$wb_selc) || (!$wb_conn))
25
                die('<h1>Fehler</h1>Es konnte keine Verbindung zu dem Datenbankserver hergestellt werden.<br><br>Bitte pr&uuml;fen Sie den Serverstatus und die G&uuml;ltigkeit der Konfigurationsdatei &quot;includes/config.inc.php&quot;.<br><br>MySQL meldet folgendes:<br><br><code>'.mysql_errno().': '.mysql_error().'</code>');
26
}
27
 
28
function db_query($inp, $halte_an_bei_fehler = true)
29
{
30
        global $configuration;
31
        global $WBConfig;
32
 
33
        dbg_log_db_query($inp);
34
 
35
        if (function_exists('getmicrotime')) {
36
                global $mysql_count;
37
                $mysql_count++;
38
                $ss = getmicrotime();
39
        }
40
 
41
        if ($WBConfig->getMySQLUseMySQLI())
42
                $x = @mysqli_query($inp);
43
        else
44
                $x = @mysql_query($inp);
45
 
46
        if (function_exists('getmicrotime')) {
47
                $ee = getmicrotime();
48
                global $mysql_time;
49
                $mysql_time += $ee-$ss;
50
        }
51
 
52
        if ($halte_an_bei_fehler)
53
        {
54
                if ($WBConfig->getMySQLUseMySQLI())
55
                        $e = @mysqli_error();
56
                else
57
                        $e = @mysql_error();
58
 
59
                if ($e != '')
60
                {
10 daniel-mar 61
                        $mess = '<b>MySQL-Fehler!</b><br><br>Folgender MySQL-Fehler ist aufgetreten:<br><br><code>'.$e.'</code><br><br>Folgende Query wurde ausgef&uuml;hrt:<br><br><code>'.wb_htmlentities($inp).'</code><br><br>Die Scriptausf&uuml;hrung wurde aus Sicherheitsgr&uuml;nden abgebrochen.';
1 daniel-mar 62
 
63
                        global $modul;
64
                        global $m2;
65
 
66
                        $m = '';
67
 
68
                        if ((isset($modul)) && ($modul != ''))
69
                                $m = $modul;
70
                        else
71
                                $m = '';
72
 
73
                        if ((isset($m2)) && ($m2 != ''))
74
                        {
75
                                if ($m2 == '')
76
                                        $z = $m2.'?';
77
                                else
78
                                        $z = ' ('.$m2.'?)';
79
                        }
80
                        else
81
                        {
82
                                $z = '';
83
                        }
84
 
85
                        if (function_exists('fehler_melden')) fehler_melden($m.$z, $mess);
86
 
87
                        die($mess);
88
                }
89
        }
90
 
91
        return $x;
92
}
93
 
94
function db_fetch($inp)
95
{
96
        global $WBConfig;
97
 
98
        if (function_exists('getmicrotime')) $ss = getmicrotime();
99
 
100
        if ($WBConfig->getMySQLUseMySQLI())
101
                return @mysqli_fetch_array($inp);
102
        else
103
                return @mysql_fetch_array($inp);
104
 
105
        if (function_exists('getmicrotime')) {
106
                $ee = getmicrotime();
107
                global $mysql_time;
108
                $mysql_time += $ee-$ss;
109
        }
110
}
111
 
112
function db_escape($inp)
113
{
114
        global $WBConfig;
115
 
116
        if ($WBConfig->getMySQLUseMySQLI())
117
                return @mysqli_real_escape_string($inp);
118
        else
119
                return @mysql_real_escape_string($inp);
120
}
121
 
122
function db_simple_escape($inp)
123
{
124
        global $WBConfig;
125
 
126
        if ($WBConfig->getMySQLUseMySQLI())
127
                return @mysqli_escape_string($inp);
128
        else
129
                return @mysql_escape_string($inp);
130
}
131
 
132
function db_num($inp)
133
{
134
        global $WBConfig;
135
 
136
        if ($WBConfig->getMySQLUseMySQLI())
137
                return @mysqli_num_rows($inp);
138
        else
139
                return @mysql_num_rows($inp);
140
}
141
 
142
function db_affected_rows()
143
{
144
        global $WBConfig;
145
 
146
        if ($WBConfig->getMySQLUseMySQLI())
147
                return @mysqli_affected_rows();
148
        else
149
                return @mysql_affected_rows();
150
}
151
 
152
function db_list_dbs()
153
{
154
        global $WBConfig;
155
 
156
        if ($WBConfig->getMySQLUseMySQLI())
157
                return @mysqli_list_dbs();
158
        else
159
                return @mysql_list_dbs();
160
}
161
 
162
function db_list_tables($db)
163
{
164
        global $WBConfig;
165
 
166
        if ($WBConfig->getMySQLUseMySQLI())
167
                return @mysqli_list_tables($db);
168
        else
169
                return @mysql_list_tables($db);
170
}
171
 
172
function db_error()
173
{
174
        global $WBConfig;
175
 
176
        if ($WBConfig->getMySQLUseMySQLI())
177
                return @mysqli_error();
178
        else
179
                return @mysql_error();
180
}
181
 
182
function db_disconnect()
183
{
184
        global $WBConfig;
185
        @session_write_close();
186
 
187
        if ($WBConfig->getMySQLUseMySQLI())
188
                @mysqli_close();
189
        else
190
                @mysql_close();
191
}
192
 
193
function db_time()
194
{
195
        // Warum? Wenn die Zeit von PHP und MySQL verschieden ist (z.B. da auf unterschiedliche Server verteilt), gäbe es Probleme!
196
 
197
        $res = db_query("SELECT NOW()");
198
        $row = db_fetch($res);
199
 
200
        return $row[0];
201
}
202
 
203
register_shutdown_function('db_disconnect');
204
db_connect();
205
 
206
?>