Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by Gott ( 18 years ago )
<?php
//----------------------------------------
// Datenbank-Klasse
// 
// Version 0.02 beta
// Stand 18.03.2008
//----------------------------------------

class DB {
	private $db_link;
	private $result;
	private $querycount = 0;
	
	
	//Stellt eine Verbindung zur Datenbank her
	public function __construct( $dbhost, $dbuser, $dbpswd, $dbname) {
		if(!$this->db_link = @mysql_connect($dbhost, $dbuser, $dbpswd)) {
			die("Fehler beim Verbinden: ".mysql_error());
		} else {
			if(!mysql_select_db($dbname, $this->db_link)) {
				die("Fehler beim Ausw&Atilde;&curren;hlen der Datenbank: ".mysql_error());
			}
		}
	}
	
	public function __destruct() {
		@mysql_close($this->db_link);
	}
	
	// Liefert ein Array mit den Datenbank-Eintr&Atilde;&curren;gen
	public function getRes($sql) {
		if(!$this->result = mysql_query(mysql_escape_string($sql), $this->db_link)) {
			die("Fehler in der Abfrage: ".mysql_error());
		} else {
			while($hilf_array = mysql_fetch_array($this->result)) {	
				$array[] = $hilf_array;
			}
			$this->querycount ++;
			return $array;
		}
	}
	
	// Liefert einen einzelnen Datensatz
	public function getRow($sql) {
		if(!$this->result = @mysql_query(mysql_escape_string($sql), $this->db_link)) {
			die("Fehler in der Abfrage: ".mysql_error());
		} else {
			$this->querycount ++;
			return @mysql_fetch_array($this->result);
		}
	}
	
	//Liefert eine einzelne Variable
	public function getVar($sql) {
		if(!$this->result = mysql_query(mysql_escape_string($sql), $this->db_link)) {
			die("Fehler in der Abfrage: ".mysql_error());
		} else {
			$row = @mysql_fetch_row($this->result);
			$this->querycount ++;
			return $row[0];
		}
	}
	
	public function numRow($sql) {
		if(!$this->result = mysql_query(mysql_escape_string($sql), $this->db_link)) {
			die("Fehler in der Abfrage: ".mysql_error());
		} else {
			return mysql_num_rows($this->result);
		}
	}
	
	public function retNumber() {
		return $this->number;
	}
}
?>

 

Revise this Paste

Your Name: Code Language: