<?php
/******************************************************************
* $Id: mysql.php,v 1.13 2003/09/12 14:47:58 allowee Exp $
*
* Copyright (C) 2001-2003 PMS Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* The "GNU General Public License" (GPL) is available at
* http://www.gnu.org/copyleft/gpl.html.
******************************************************************/
class database {
function connect(){
$this->db_conn = @mysql_connect($this->Host, $this->DBUser, $this->DBPass) or $this->halt("Can't connect to the db server");
$this->db_sel = @mysql_select_db($this->DBName, $this->db_conn) or $this->halt("Can't select the db");
unset($this->DBPass);
}
function query($query_id){
global $query_count, $debug;
$query_count++;
echo ($debug) ? "(<font color='green'>".$query_count."</font>)\n" : "";
$query_id = $this->check_query($query_id);
$result_id = @mysql_query($query_id, $this->db_conn) or $this->halt("SQL Query failed: ".$query_id);
return $result_id;
}
function query_no($query_id){
global $query_count2, $debug;
$query_count2++;
echo ($debug) ? "[<font color='red'>".$query_count2."</font>]\n" : "";
$query_id = $this->check_query($query_id);
@mysql_query($query_id, $this->db_conn) or $this->halt("SQL without return failed: ".$query_id);
}
function close(){
@mysql_close($this->db_conn);
}
function check_query ($query) {
// if (stristr($query, ";")) {
// echo "<b>BAD HACKER!!</b> No database cracking for you today!";
// exit;
// }
return $query;
}
function halt($msg) {
if (defined('IN_ADMIN')) {
include_once ('./../includes/functions_mail.php');
} else {
include_once ('./includes/functions_mail.php');
}
$this->errdesc = @mysql_error();
$this->errno = @mysql_errno();
// prints warning message when there is an error
global $sitename, $siteaddr, $sitemail, $scriptpath, $mail_errors;
$message="Database error in " . $sitename. "\n\n$msg\n\n";
$message.="mysql error: " . $this->errdesc . "\n";
$message.="mysql error number: " . $this->errno . "\n\n";
$message.="Date: "hide@address.com("l dS of F Y h:i:s A")."\n";
$message.="Script: ".$siteaddr . $_SERVER['REQUEST_URI'] . "\n";
$message.="Referer: ".((isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '')."\n";
$message.="Host: ".HOST."\n";
if ($mail_errors == "1") {
@mailer ($sitemail, $sitename." Database error!", $message, "From: ".$sitemail);
}
echo "<html><head><title>".$sitename." Database Error</title><style>P,BODY{FONT-FAMILY:tahoma,arial,sans-serif;FONT-SIZE:11px;}</style><body>\n\n<!-- ".$message." -->\n\n";
echo "</table></td></tr></table></form>\n<blockquote><p> </p><p><b>There seems to have been a slight problem with the ".$sitename." database.</b><br>\n";
echo "Please try again by pressing the <a href=\"javascript:window.location=window.location;\">refresh</a> button in your browser.</p>";
echo "An E-Mail has been dispatched to our Technical Staff.</p>";
echo "<p>We apologise for any inconvenience.</p>";
exit;
}
}