<?php 

class database{
	
	public $host = DB_HOST; 
	public $user = DB_USER; 
	public $pass = DB_PASS; 
	public $db_name = DB_NAME; 
	
	public $link; 
	public $error; 
	
	//Creating constructor
	public function __construct(){
	
		$this->connect();
	}
	
	//Connecting 
	private function connect(){
	
		$this->link = new mysqli($this->host, $this->user, $this->pass, $this->db_name);
		
		if(!$this->link){
			$this->error = "Connection Failed: ". $this->link->connect_error;
			return false;
		}
	
	}
	
	//select query
	public function select($query){
		
		$result = $this->link->query($query);
		
		if($result->num_rows > 0){
		return $result;
		} else {
		return false;
		}
	}
	
	//insert query 
	public function insert($query){
		
		$insert = $this->link->query($query);
		if($insert){
		header("location: index.php?msg=Eintrag hinzugefügt!");
		}
		else {
		echo "Konnte nicht eingetragen werden!";
		}
		}
		
	// update query
		public function update($query){
		
		$update = $this->link->query($query);
		if($update){
		header("location: index.php?msg=Eintrag &uuml;berarbitet!");
		}
		else {
		echo "Konnte nicht &uuml;berarbeitet werden!";
		}
		}
		
		// delete query
		public function delete($query){
		
		$delete = $this->link->query($query);
		if($delete){
		header("location: index.php?msg=Eintrag  gel&ouml;scht!");
		}
		else {
		echo "Konnte nicht gel&ouml;scht werden!";
		}
		}

}