<?php
/*
 * Created on 07.04.2012
 * Oliver Soop(osoop1@ut.ee)
 */
 
 class URLDatabase {

	private static $instance;
	private $resource;
	private $lastQuery;

	private function URLDatabase() {
	}

	public static function getInstance() {
		if (isset (self :: $instance)) {
			return self :: $instance;
		} else {
			self :: $instance = new URLDatabase();
			return self :: $instance;
		}
	}

	private function check_error() {
		if ($this->resource->connect_errno) {
			echo "connection viga";
			$myFile = "log.txt";
			$fh = fopen($myFile, 'a');
			fwrite($fh, $this->resource->connect_errno . "\n");
			fclose($fh);
		}
	}

	public function connect() {
		$this->resource = new mysqli('localhost', 'kasutaja', 'parool');

		$this->check_error();
		if (!$this->resource) {
			die('Could not connect: ' . mysql_error());
		}

		if (!$this->resource->select_db("ekktt_crawler_urls")) {
			die('Can\'t use ekktt : ' . mysql_error());
		}
		$this->resource->set_charset("utf8");
	}

	public function close() {
		$this->resource->close or die(mysql_error());
	}

	public function getResource() {
		return $this->resource;
	}

}
?>
