File:
1.00.3a/server/base/nats.db.inc.php (
View as Code)
1: 2: /* -------------------------------------------------------------
3: This file is part of FreeNATS
4:
5: FreeNATS is (C) Copyright 2008 PurplePixie Systems
6:
7: FreeNATS is free software: you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation, either version 3 of the License, or
10: (at your option) any later version.
11:
12: FreeNATS is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with Foobar. If not, see www.gnu.org/licenses
19:
20: For more information see www.purplepixie.org/freenats
21: -------------------------------------------------------------- */
22:
23: function ss($s) // safestring
24: {
25: return mysql_escape_string($s);
26: }
27:
28: class TNATS_DB
29: {
30: var $connected=false;
31: var $sql=0;
32:
33: function Connect()
34: {
35: global $fnCfg;
36: $this->sql=mysql_connect($fnCfg['db.server'],$fnCfg['db.username'],$fnCfg['db.password'])
37: or die("Cannot connect to MySQL server");
38: mysql_select_db($fnCfg['db.database'])
39: or die("Cannot select MySQL database");
40: $this->connected=true;
41: return $this->sql;
42: }
43:
44: function Disconnect()
45: {
46: mysql_close($this->sql);
47: $this->sql=0;
48: $this->connected=false;
49: }
50:
51: function Query($query,$debugerror=true)
52: {
53: global $NATS;
54: if (!$this->connected) return -1;
55: $result=mysql_query($query,$this->sql);
56: if (mysql_errno($this->sql)>0)
57: {
58: $err=mysql_error($this->sql)." (".mysql_errno($this->sql).")";
59: if (isset($NATS))
60: {
61: $NATS->Event("Query Failed: ".$query,2,"DB","Query");
62: $NATS->Event("Query Error: ".$err,2,"DB","Query");
63: }
64: }
65: return $result;
66: }
67:
68: function Free($result)
69: {
70: mysql_free_result($result);
71: }
72:
73: function Fetch_Array($result)
74: {
75: return mysql_fetch_array($result);
76: }
77:
78: function Affected_Rows()
79: {
80: return mysql_affected_rows($this->sql);
81: }
82:
83: function Insert_Id()
84: {
85: return mysql_insert_id($this->sql);
86: }
87:
88: function Num_Rows($result)
89: {
90: return mysql_num_rows($result);
91: }
92:
93: function Error()
94: {
95: if (mysql_errno($this->sql)==0) return false;
96: return true;
97: }
98:
99: function Error_Number()
100: {
101: return mysql_errno($this->sql);
102: }
103:
104: function Error_String()
105: {
106: return mysql_error($this->sql)." (".$this->Error_Number().")";
107: }
108: }