<?php

class db {

function db() {
//ide johetnek az alapertelmezett dolgok
//$this->database = "test";
include ("config.php");

$this->set_params($host, $user, $pwd, $database);
$this->connect();
$this->select_db();
mysql_query( "set names 'latin2'" );
mysql_query( "set character set 'latin2'" );
}


function set_params($host, $user, $pwd, $database) {
$this->host=$host;
$this->user=$user;
$this->pwd=$pwd;
$this->database=$database;
}

// a last_insert-re kene valami megoldas
function get_link() {
return $this->db_link;
}


function display_message($msg) {
printf("<BLOCKQUOTE><H3><FONT FACE=\"courier\" COLOR=\"#CC0000\">%s</FONT></H3></BLOCKQUOTE>\n", $msg);
}


function errorhandler() {
if ($this->error) $this->display_message($this->error);
if ($this->mysql_errno) $this->display_message($this->mysql_errno);
if ($this->mysql_error) $this->display_message($this->mysql_error);
}


function connect() {
if (!($this->db_link=@mysql_pconnect($this->host, $this->user, $this->pwd))) {
	$this->error=sprintf("Error connecting to host '%s', by user '%s'!", $this->host, $this->user);
	$this->errorhandler();
	exit();
}
}


function select_db() {
if (!mysql_select_db($this->database, $this->db_link)) {
	$this->error=sprintf("Error in selecting '%s' database!", $this->database);
	$this->mysql_errno=sprintf("Error number: %d", mysql_errno($this->db_link));
	$this->mysql_error=sprintf("Error description: %s", mysql_error($this->db_link));
	$this->errorhandler();
	exit();
}
}


function execute() {
if (!($this->result=mysql_query($this->stmt, $this->db_link))) {
	$this->error=sprintf("Error in executing >> %s << stmt!", $this->stmt) ;
	$this->mysql_errno=sprintf("Error number: %d", mysql_errno($this->db_link));
	$this->mysql_error=sprintf("Error description: %s", mysql_error($this->db_link));
	$this->errorhandler();
	exit();
}

}


function query($stmt) {
$this->stmt=$stmt;

$this->execute();
return $this->result;
}

} // end class
error_reporting(0);
?>
