<?php

include_once('MySQL.Config.php');

class ConnectionFactory
{
	//attributes LOCAL
	public static $server;
	public static $database;
	public static $user;
	public static $pass;
	public static $connection;
	
	public $mdb2;
	
	public static $environment = 'HML';
	
	public function CreateConnection()
	{
		try
		{
			$config = new Config();
			$config->Set(self::$environment);
			
			self::$server = $config->server;
			self::$user = $config->user;
			self::$pass = $config->pass;
			self::$database = $config->database;

			self::$connection = mysql_connect(self::$server, self::$user,self::$pass);
			self::SetDataBase(self::$connection);					
		}
		catch(Exception $err)
		{
			echo("Connection error: " . mysql_error());
			return null;
		}
	}
	
	public function SetDataBase($connection)
	{
		mysql_select_db(self::$database,$connection);
	}
	
	public function ExecuteSelect($query)
	{
		self::CreateConnection();
		$result = mysql_query($query);
		return $result;
	}
	
	public function ExecuteInsert($query)
	{
		self::CreateConnection();
		mysql_query($query);
		$result = mysql_insert_id(self::$connection);
		return $result;
	}
	
	public function ExecuteAffected($query)
	{
		self::CreateConnection();
		mysql_query($query);
		$result = mysql_affected_rows(self::$connection);
		return $result;
	}
}

?>