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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
<?php if (!defined('_VALID_TCPRO')) exit ('No direct access allowed!'); /** * db.class.php * * Interface to the TeamCal Pro database * * @package TeamCalPro * @version 3.3.001 * @author George Lewe <george@lewe.com> * @copyright Copyright (c) 2004-2010 by George Lewe * @link http://www.lewe.com * @license http://www.lewe.com/tcpro/doc/license.txt Extended GNU Public License */
/** * Make sure the class hasn't been loaded yet */ if (!class_exists("myDB")) { /** * Interface to the TeamCal Pro database * @package TeamCalPro */ class myDB { var $db_type = ''; var $db_server = ''; var $db_name = ''; var $db_user = ''; var $db_pass = ''; var $db_persistent = ''; var $db_handle = ''; var $db_errortxt = '';
/** * Constructor reading server and database information from the * configuration file. */ function myDB() { global $CONF; $this->db_type = $CONF['db_type']; $this->db_server = $CONF['db_server']; $this->db_name = $CONF['db_name']; $this->db_user = $CONF['db_user']; $this->db_pass = $CONF['db_pass']; $this->db_persistent = $CONF['db_persistent']; $this->db_connect(); }
/** * Connects to the database server and to the database */ function db_connect() { switch ($this->db_type) { case 1 : // MySQL if ($this->db_persistent) { $this->db_handle = @ mysql_pconnect($this->db_server, $this->db_user, $this->db_pass); } else { $this->db_handle = @ mysql_connect($this->db_server, $this->db_user, $this->db_pass); } if (!$this->db_handle) { $errtxt = "Connecting to mySQL server " . $this->db_server . " failed."; $this->db_error($errtxt, "db_connect()", true); return; } if (!@ mysql_select_db($this->db_name, $this->db_handle)) { $errtxt = " Error: Connection to MySQL database " . $this->db_server . "/" . $this->db_name . " failed.<BR> Code: " . @ mysql_errno($this->db_handle) . ",<BR> Message: " . @ mysql_error($this->db_handle) . " "; $this->db_error($errtxt, "db_connect()", true); } break; } }
/** * Executes a query on the database * * @param string $query String containing the query to be executed. Will be initialized to empty if not passed * @return integer Result of the query */ function db_query($query = '') { switch ($this->db_type) { case 1 : // MySQL $result = mysql_query($query, $this->db_handle); if (!$result) { echo "Error: A problem was encountered while executing this query:<br><br>\n\n$query<br><br>\n\n"; die("Error: Fatal database error!<br>\n"); } break; } return $result; }
/** * Returns the number of records based on the result of a query * * @param integer $result Result of the query * @return integer Number of records matching the query */ function db_numrows($result) { switch ($this->db_type) { case 1 : // MySQL return mysql_num_rows($result); } }
/** * Returns an array containing the matching records of a query * * @param integer $result Result of the query * @param integer $type MYSQL_ASSOC, MYSQL_NUM or MYSQL_BOTH, defining the type of index for the returned array * @return array Array of records matching the query */ function db_fetch_array(& $result, $type = MYSQL_BOTH) { switch ($this->db_type) { case 1 : // MySQL return mysql_fetch_array($result, $type); } }
/** * Sending an error message to the browser * * @param string $errtxt Error text to display * @param string $func Name of the method in which this error ocurred * @param boolean $die Switch whether to die with this error or to procede after displayed */ function db_error($errtxt, $func, $die) { $this->db_errortxt = " <table class=\"err\">\n <tr>\n <td class=\"err-header\">TeamCal Pro Controlled Error Exit</td>\n </tr>\n <tr>\n <td class=\"err-body\">\n <span class=\"modcap\">Module:</span> <span class=\"module\">class.db.php</span><br>\n <span class=\"classcap\">Class:</span> <span class=\"class\">myDB</span><br>\n <span class=\"funcap\">Function:</span> <span class=\"function\"> " . $func . "</span><br><br>\n <span class=\"errortext\"> " . $errtxt . "</span><br><br>\n"; if ($die) $this->db_errortxt .= "<span class=\"erraction\">Execution halted!</span><br>\n"; $this->db_errortxt .= " </td>\n </tr>\n </table>\n <br>"; if ($die) die($this->db_errortxt); else echo $this->db_errortxt; } } } ?>
|