<?php
require("config.php");
class cl_extended_database
{
var $started = false;
var $debug = false;
var $var_sql;
var $var_result;
var $var_error;
var $var_errno;
var $var_link;
var $db_connected = false;
var $db_selected = false;
function __construct()
{
global $CMS;
$this->connect($CMS["mysql"]["host"], $CMS["mysql"]["user"], $CMS["mysql"]["pass"]);
$this->select_db($CMS["mysql"]["db"]);
}
function connect($host, $user, $password)
{
if ($this->debug) {
echo "cl_database::connect('$host','$user','$password');<br>";
}
$this->var_link = mysql_connect($host, $user, $password);
$this->db_connected = true;
}
function __destruct()
{
if ($this->debug) {
echo "cl_database::__destruct();<br>";
}
@mysql_free_result($this->var_result);
@mysql_close($this->var_link);
}
function select_db($db)
{
if ($this->debug) {
echo "cl_database::select_db();<br>";
}
$db_sel = mysql_select_db($db, $this->var_link);
if (!$db_sel) {
$this->var_sql = "SELECT DB '$db';";
$this->var_error = mysql_error($this->var_link);
$this->var_errno = mysql_errno($this->var_link);
$this->var_result = false; //this->error() == true;
} else {
$this->var_sql = "SELECT DB '$db';";
$this->var_result = true; //this->error() == false;
}
$this->db_selected = !$this->var_result;
}
function query($sql)
{
if ($this->debug) {
echo "cl_database::query('$sql');<br>";
}
// echo "Query: <b>$sql</b><br>";
// echo "cl_database::query('$sql');<br>";
$db_query = new cl_extended_database;
$this->var_sql = trim($sql);
$this->var_result = mysql_query($this->var_sql, $db_query->var_link);
if (!$this->var_result) {
$this->var_errno = mysql_errno($db_query->var_link);
$this->var_error = mysql_error($db_query->var_link);
}
unset($db_query);
}
function error()
{
if ($this->debug) {
echo "cl_database::error();<br>";
}
$tmp = $this->var_result;
$tmp = (bool)$tmp;
$tmp = !$tmp;
return $tmp;
}
function geterror()
{
if ($this->debug) {
echo "cl_database::geterror();<br>";
}
if ($this->error()) {
$str = "<br>\n";
$str .= "Query: <b>" . $this->var_sql . "</b><br>\n";
$str .= "Error: <b>" . $this->var_error . "</b><br>\n";
$str .= "Error Number: <b>" . $this->var_errno . "</b><br>\n";
} else {
$str = "Error: No Error!<br>";
}
return $str;
}
function numrows()
{
if ($this->debug) {
echo "cl_database::numrows();<br>";
}
if ($this->error()) {
$return = -1;
} else {
$return = mysql_num_rows($this->var_result);
}
return $return;
}
function fetch()
{
if ($this->debug) {
echo "cl_database::fetch();<br>";
}
if ($this->error()) {
echo "<br>\nEs trat ein Fehler auf. Bitte ?berpr?fen sie ihr";
echo "MySQL-Query.\n<br>";
$return = null;
} else {
$return = mysql_fetch_array($this->var_result);
}
return $return;
}
function err()
{
if ($this->debug) {
echo "cl_database::err();<br>";
}
if ($this->error()) {
echo $this->geterror();
}
}
function reinit()
{
$this->__destruct();
$this->__construct();
}
function dbclose()
{
$this->__destruct();
}
function start()
{
global $CMS;
if (!$this->started) {
if ($this->db_connected == false) {
$this->connect($CMS["mysql"]["host"], $CMS["mysql"]["user"], $CMS["mysql"]["pass"]);
$this->db_connected = true;
}
if ($this->db_selected == false) {
$this->select_db($CMS["mysql"]["db"]);
$this->db_selected == $this->error();
}
$this->started = true;
}
}
?>