<?
class get_db {
var $islinked = 0;
var $iserror = 0;
var $reporterror = array();
var $islinux = 0;
var $server = "localhost";
var $database = "forum";
var $user = "root";
var $password = "";
function connect() {
if(1 == $this->$islinux) {
$use_pconnect = 0;
global $use_pconnect;
$starttime_connect = microtime();
$test_connect = mysql_connect($this->server, $this->user, $this->password);
if($test_connect) {
$could_connect = 1;
global $could_connect;
}
else {
$couldconncet = 1;
global $could_connect;
}
if($couldconnect == 1) {
$use_pconnect = 1;
global $use_pconnect;
}
}
if(0 == $this->$islinux) {
$use_pconnect = 0;
}
if(0 == $this->islinked) {
if($password == "") {
if($use_pconnect == 0) {
$this->link_id = mysql_pconnect($this->server, $this->user);
}
else {
$this->link_id = mysql_connect($this->server, $this->user);
}
}
else {
if($use_pconnect == 1) {
$this->link_id = mysql_pconnect($this->server, $this->user, $this->password);
}
else {
$this->link_id = mysql_connect($this->server, $this->user, $this->password);
}
}
}
if(!$this->link_id) {
$this->stopm("Couldn´t connect to: ".$this->server.
" with ".$this->user."".mysql_error."reason");
}
if(!$this->database == "") {
$this->db_query = mysql_db_query($this->database, $this->link_id);
$this->stopm("Couldn´t connect to".$this->database);
}
}
function errors() {
$this->error = mysql_error());
return $this->error;
}
function errno() {
$this->errno = mysql_errno());
return $this->errno;
}
function reporterrno() {
$this->errno = mysql_errno());
$this->file = db_logs.txt;
if(file_exists($this->file)) {
$this->openlogfile = fopen($this->file, a+);
if(feof($this->openlogfile)) {
fputs($this->openlogfile, date("d.M.Y h:m:s", time())."<br>".$REMOTE_ADDR."<br>\n".$this->errno);
fclose($this->openlogfile);
}
}
else {
$this->openlogfile = fopen($this->file, a+);
if(feof($this->openlogfile)) {
fputs($this->openlogfile, date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."<br>n");
fclose($this->openlogfile);
}
@mail("support@joesboard.de", 'Mysql_error: ".$this->errno."', date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."<br>\n".$this->errno."");
}
function db_select($database) {
$this->database = $database;
$this->db_query = mysql_select_db($this->database, $this->link_id);
$this->stopm("Couldn´t connect to".$this-database."reason".$this->error.);
}
function db_query($string_query) {
$this->query = mysql_query($string_query, $this->link_id);
if(!$this->query) {
$this->stopm("Invalid Mysql_query: ".$string_query)
}
return $this->query;
}
function fetch_array($string_query) {
if (isset($query_string)) {
$this->fetch_data = mysql_fetch_array($this->query, $this->link_id);
if(empty($string_query) {
$this->stopm("Query was emtpy or wrong".$this->error.");
}
if(!$this->fetch_data) {
$this->stopm("Query was emtpy or wrong".$this->error.");
}
else {
return $this->fetch_data;
}
}
function stopm($msg) {
$this->error=mysql_error();
$this->errno=mysql_errno();
if ($this->reporterror == 1) {
$message="Database error in $this->appname: $msg\n";
$message.="mysql error: $this->error\n";
$message.="mysql error number: $this->errno\n";
$message.="Date: ".date("l dS of F Y h:i:s A")."\n";
$message.="Script: ".getenv("REQUEST_URI")."\n";
$message.="Referer: ".getenv("HTTP_REFERER")."\n";
@mail (support@joesboard.de,"$this->appshortname Database error!",$message);
echo "\n<!-- $message -->\n";
echo "</td></tr></table>\n<p>Es sind Probleme mit der Datenbank aufgetreten.\n";
echo "Versuchen sie es erneut in dem sie den Refresh Button des Browser nutzen.</p>";
echo "Es wurde eine Email an unseren Techniker gesendet<a href=\"mailto:$technicalemail\">Techniker</a>, der mit diesem Link kontaktiert werden kann, sofern der Fehler erneut auftritt.</p>";
echo "<p>Wir bitten vielmals um Entschuldigung.</p>";
die("");
}
}