File: 0.02.30a/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) 52: { 53: if (!$this->connected) return -1; 54: return mysql_query($query,$this->sql); 55: } 56: 57: function Free($result) 58: { 59: mysql_free_result($result); 60: } 61: 62: function Fetch_Array($result) 63: { 64: return mysql_fetch_array($result); 65: } 66: 67: function Affected_Rows() 68: { 69: return mysql_affected_rows(); 70: } 71: 72: function Insert_Id() 73: { 74: return mysql_insert_id(); 75: } 76: 77: function Num_Rows($result) 78: { 79: return mysql_num_rows($result); 80: } 81: 82: }