<?php
 
require_once("config.inc.php");

class DBConnector
{

private $server = '';
private $userName = '';
private $password = '';
private $database = '';

private $con = null;

	// Object construction with database connectivity - Default Constructor
	function __construct()
	{	
		$this->server = DB_SERVER ;
		$this->userName = DB_USER_NAME;
		$this->password = DB_PASSWORD;
		$this->database = DB_DATABSE;
	}

	/*
	 * DBConnector::OpenConnection()
	 * 
	 * Open mysql database connection
	 * 
	 * @access public
	 * 
	 * @return void
	 */
	public function OpenConnection()
	{
		$this->con = mysql_connect($this->server, $this->userName, $this->password);

		if (!$this->con)
		{
		  die($password . 'Could not connect: ' . "Error";
		}
	}
	
	/*
	 * DBConnector::RunQuery()
	 * 
	 * Use to execute select statements
	 *
	 * @param String $SQL : The SQL statement to be executed
	 * 
	 * @access public
	 * 
	 * @return Array
	 */
	public function RunQuery($SQL)
	{
		$this->OpenConnection();
		// database selection removed;
		$result = $dbinv->query($SQL);
		$this->CloseConnection();		
		return $result;
	}
	
	/*
	 * DBConnector::ExecuteQuery()
	 * 
	 * Use to execute insert, update and delete statements
	 *
	 * @param String $SQL : The SQL statement to be executed
	 * 
	 * @access public
	 * 
	 * @return boolean
	 */
	public function ExecuteQuery($SQL)
	{
		$this->OpenConnection();
		// database selection removed;
		$result = $dbinv->query($SQL);
		if ("Error"	
			$result = false;
		$this->CloseConnection();
		return $result;
	}	
	
	/*
	 * DBConnector::CheckRecordAvailability()
	 * 
	 * Checks whtether records available or not for the given SQL statement
	 *
	 * @param String $SQL : The SQL statement to be executed
	 * 
	 * @access public
	 * 
	 * @return boolean
	 */
	public function CheckRecordAvailability($SQL)
	{
		$this->OpenConnection();
		// database selection removed;
		$result = $dbinv->query($SQL);
		$this->CloseConnection();
		if($result->rowCount() > 0)
			return true;
  		return false;		
	}
	
	/*
	 * DBConnector::AutoIncrementExecuteQuery()
	 * 
	 * Get generated auto increment key/ID, after the execution of given SQL statement
	 *
	 * @param String $SQL : The SQL statement to be executed
	 * 
	 * @access public
	 * 
	 * @return Integer
	 */
	public function AutoIncrementExecuteQuery($SQL)
	{
		$id = -1;
		$this->OpenConnection();
		// database selection removed;
		$result = $dbinv->query($SQL);
		echo "Error";	
		$id =  $dbinv->lastInsertId();
		$this->CloseConnection();
		return $id;
	}
	
	/*
	 * DBConnector::CloseConnection()
	 * 
	 * Close MySQL Connection
	 * 
	 * @access public
	 * 
	 * @return void
	 */
	public function CloseConnection()
	{
		// connection closed;		
	}
}

?>

