Hostname = $Hostname; $this->Username = $Username; $this->Password = $Password; $this->Database = $Database; } // Connect to MySQL database function connect(){ $this->conn = mysql_connect($this->Hostname, $this->Username, $this->Password); mysql_select_db($this->Database); } // Return the MySQL Error number and text, if any function Error(){ if (mysql_error($this->conn)) return mysql_errno($this->conn) . ': ' . mysql_error($this->conn); else return false; } // Disconnect from MySQL database (do this in footer.inc) function disconnect(){ return mysql_close($this->conn); } // See if we are connected and return boolean function connected(){ if ($this->conn) return true; else return false; } // Query MySQL function Query($Query){ $result = @mysql_query($Query, $this->conn); $this->QueryCount++; return $result; } // Escape a string to make it safe for MySQL function Escape($str){ return mysql_real_escape_string($str); } // Query MySQL and return object of first row (all columns) function rQuery($sql){ $sql = $this->Query($sql); if (!$sql) return false; return mysql_fetch_object($sql); } // Query MySQL and return associative array of first row (all columns) function aQuery($sql){ $sql = mysql_query($sql); if (!$sql) return false; return mysql_fetch_assoc($sql); } // Query MySQL and return array of first column (all rows) function lQuery($sql){ $sql = $this->Query($sql); if (!$sql) return false; while ($line = $this->row($sql)) $lines[] = $line[0]; return $lines; } // Query MySQL and return contents of first column in first row function oQuery($sql){ $sql = $this->Query($sql); if (!$sql) return false; if ($sql) list($sql) = $this->row($sql); else $sql = ''; return $sql; } // Fetch a row function row($sql){ if (!$sql) return false; return mysql_fetch_row($sql); } // Fetch an object function obj($sql){ if (!$sql) return false; return mysql_fetch_object($sql); } // Fetch an associative array function arr($sql){ if (!$sql) return false; return mysql_fetch_assoc($sql); } // Fetch the entire table into a nested array function tQuery($Query){ $sql = $this->Query($Query); if (!$sql) return false; while ($row = mysql_fetch_assoc($sql)) $rows[] = $row; return $rows; } // Fetch the entire table as an array of objects (faster?) function toQuery($Query){ $sql = $this->Query($Query); if (!$sql) return false; while ($row = mysql_fetch_object($sql)) $rows[] = $row; return $rows; } } $db = new mysql_db($Config['Hostname'], $Config['Username'], $Config['Password'], $Config['Database']); $db->connect(); ?>