<?php
	/**
	* Open a connection with the database server using mssql extension.
	*
	* @copyright Trusto Tech 2015-2016
	* @author  Taha Sayyad <info@trustotech.com>
	* @package System\Database\Adapters
	*/
	class MsSQLAdapter extends DBConnectionParameters implements DBAdapterInterface {

		private $_DBConnection;
		
		public function __construct() {
            parent::_setParameters();
            self::connect();
		}
		
		public function query($query) {
			if (empty($query))
				return false;
			return mssql_query($query);
		}
		
		public function rowsno($result) {
			return mssql_num_rows($result);
		}
		
		public function setNames() {
			self::query("SET NAMES 'utf8'"); 
			self::query('SET CHARACTER SET utf8'); 
		}
		
		public function fetch($result) {
			return mssql_fetch_array($result);
		}
		
		public function id() {}

		public function assoc($result) {
			return mssql_fetch_assoc($result);
		}

		public function getConnectionObject() {
			return $this->_DBConnection;
		}

		private function connect() {
			$this->_DBConnection = mssql_connect(parent::_getDBHostname(), parent::_getDBUsername(), parent::_getDBPassword());
			if ($this->_DBConnection) {
				if (mssql_select_db(parent::_getDBName(), $this->_DBConnection))
					return false;
			} else
				return false;
		}

	}