<?php
	Class PHPRC_PDO_MSSQL
	{
		/**
		 * Returns PDOConnection. (Do not pass any parameter if you want to use the SQL constants in PHPSettings file)
		 * @param String $DATA_SOURCE <br />[Optional]DataSource to connect e.g. LocalHost.<br />
		 * @param String $DATABASE_NAME<br />[Optional]Name of database to load.<br />
		 * @param String $DATABASE_USER<br />[Optional]SQL database authentication username.<br />
		 * @param String $DATABASE_PASSWORD<br />[Optional]SQL database authentication password.<br />
		 * @return PDOHandle <br />PDO Handle connected with requested database.<br />
		 */
		Public Static Function REF_CONNECT($DATA_SOURCE = "", $DATABASE_NAME = "", $DATABASE_USER = "", $DATABASE_PASSWORD = "")
		{		
			Try 
			{
				if
				(
					PHPVC_STR::VAR_IS_BLANK($DATA_SOURCE) === TRUE &&
					PHPVC_STR::VAR_IS_BLANK($DATABASE_NAME) === TRUE &&
					PHPVC_STR::VAR_IS_BLANK($DATABASE_USER) === TRUE &&
					PHPVC_STR::VAR_IS_BLANK($DATABASE_PASSWORD) === TRUE
				)
				{
					$DATA_SOURCE = PHPSET::$MSSQL_DATA_SOURCE;
					$DATABASE_NAME = PHPSET::$MSSQL_DATABASE_NAME;
					$DATABASE_USER = PHPSET::$MSSQL_DATABASE_USER;
					$DATABASE_PASSWORD = PHPSET::$MSSQL_DATABASE_PASSWORD;
				}
				
				Return new PDO
				(
					"sqlsrv:Server=" . $DATA_SOURCE . ";Database=" . $DATABASE_NAME, 
					$DATABASE_USER, 
					$DATABASE_PASSWORD
				);
			}
			Catch(PDOException $PDO_ERR) 
			{
				PHPVC_LOG::VAR_REPORT_ERROR($PDO_ERR, 0);
				PHPRC_HEADERS::REF_503_SERVICE_UNAVAILABLE();
			}
			Catch(Exception $ERR)
			{
				PHPVC_LOG::VAR_REPORT_ERROR($ERR, 0);
				PHPRC_HEADERS::REF_503_SERVICE_UNAVAILABLE();
			}
		}
	}

?>