<?php
class MySQL {
private $result = NULL;
private $counter = NULL;
public $connection = NULL;
public $id = NULL;
public $debug = NULL;
public $prefix = "";
public function __construct() {
if (defined('SQL')) {
$sql_data = json_decode(SQL);
$this->prefix = $sql_data->prefix;
$this->debug = $sql_data->debug;
$this->connection = mysql_connect($sql_data->sqlhost, $sql_data->sqluser, $sql_data->sqlpwd) or die('ERROR: Can not connect to MySQL-Server');
mysql_select_db($sql_data->sqldb, $this->connection) or die('ERROR: Can not connect to database "'.$sql_data->sqldb.'"');
}
}
public function disconnect() {
if (is_resource($this->connection === true))
mysql_close($this->connection);
}
public function query($query) {
if ($this->debug) {
$this->result = mysql_query($query, $this->connection) or die('Query failed: <br />errorno='.mysql_errno().'<br />error='.mysql_error().'<br />query='.$query);
} else {
$this->result = mysql_query($query, $this->connection) or die('Query failed!');
}
$this->id = mysql_insert_id($this->connection);
$this->counter = NULL;
}
public function fetchRow($column=false) {
if ($column === false) {
return mysql_fetch_array($this->result);
} else {
$array = mysql_fetch_array($this->result);
return $array[$column];
}
}
public function fetchAssoc() {
return mysql_fetch_assoc($this->result);
}
public function count() {
if($this->counter === NULL && is_resource($this->result) === true) {
$this->counter=mysql_num_rows($this->result);
}
return $this->counter;
}
}
?>