<?php

class MysqlConnector {
	public static $hostname = "localhost";
	public static $username = "matheus";
	public static $password = "f3a2--329";
	public static $dbName = "Planner";
	public $link;

	public function ConnectDB() {
		$this->link = new mysqli(self::$hostname, self::$username, self::$password, self::$dbName);

		if (!$this->link) {
			echo "Error: Falha ao conectar-se com o banco de dados MySQL." . PHP_EOL;
			echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
			echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;

			if(mysqli_connect_errno()){
				echo mysqli_connect_error();
			}

			exit;
		}
		
		//echo "Sucesso: Sucesso ao conectar-se com a base de dados MySQL." . PHP_EOL;

		return $this->link;
	}

	public function DisconnectDB() {
		if (isset($this->link))
			$this->link->close();
		
		$this->link = null;
	}
	
	public function GetConnectionLink() {
		if (isset($this->link)) 
		{
			return $this->link;
		}
		else
		{
			return $this->ConnectDB();
		}
	}
}

?>