<?php #lib/90_response.php

/********************************************************************************
 *	Content: Database class                                                     *
 *	Author: Nils Otterpohl                                                      *
 *	Last modification: 03.04.2023                                               *
 *	Version: alpha (object, incomplete, uncommented, untested)                  *
 ********************************************************************************/
 
class DB
{
	private $mysqli = null;
	private static $instance = null;
	
  /***** Static functions *****/
  
  public static function Get() {
  	if (is_null(self::$instance)) {
  		self::$instance = new self();
  	}
  	return self::$instance->Connection();
  }
  
  public static function LeftJoin($target, $targetShort, $targetField, $sourceShort, $sourceField) {
  	return "LEFT JOIN ".$target." ".$targetShort." ON ".$targetShort.".".$targetField."=".$sourceShort.".".$sourceField." ";
  }

  /***** Con-/Destructor *****/
  
  private function __construct() {
  	$this->mysqli = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
  	$this->mysqli->set_charset("utf8mb4");
  }
  public function __destruct() {
  	$this->mysqli->close();
  }
  
  /***** Public functions *****/
  
  public function Connection() {return $this->mysqli;}
}
