<?php

namespace Core;

use Core;

/**
 * Database access factory
 * @author fgolewski
 *
 */
class Source implements Provider
{	
	private $dsn;
	private $user;
	private $password;
	private $persistent;
	
	private $handle;
	private $statement;

	function __construct($dsn, $user = "root", $password = "", $persistent = false)
	{
		$this->dsn = $dsn;
		$this->user = $user;
		$this->password = $passsword;
		$this->persistent = $persistent;
	}
	
	function open()
	{
		global $Log;
		try {
			$handle = new PDO('mysql:host=localhost;dbname=test', $this->user, $this->password, array(
				PDO::ATTR_PERSISTENT => $this->persistent
			));
		} catch (PDOException $e) {
			if (is_object($Log)) $Log->write($e->getMessage(), 'query');
		}
		return $handle == true;
	}
	
	function close()
	{
		$this->statement = false;
		$this->handle = false;
	}
	
	function kill()
	{
		if ($this->handle)
		{
			switch ($this->layer)
			{
				case "mysql":
					$this->query('KILL CONNECTION_ID()');
				case "pgsql":
					$this->query('SELECT pg_terminate_backend(pg_backend_pid());');
			}
		}
		$this->close();
	}
	
	function query()
	{
		
	}
	
	function row()
	{		
	}
	
	function all()
	{		
	}
}
