<?php
/**
 * mssql_model.php - MSSQL modle file for batches
 *
 * @author $Author: dtong $
 * @version $Id: mssql_model.php,v 1.2 2011/02/11 09:09:27 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/

class Mssql_model extends CI_Model {
	private $db_resource = FALSE;

	function __construct() {
		parent::__construct();
	}

	function connect($server,$user,$password, $schema) {
		$this->db_resource = mssql_connect($server,$user,$password);
		if ( ! mssql_select_db($schema,$this->db_resource) ) {
			$this->db_resource = FALSE;
		}
		return $this->db_resource;
	}

	function close() {
		if ( $this->db_resource )
			mssql_close($this->db_resource);
	}

	function query($sql) {
		if ( $this->db_resource == FALSE )
			return FALSE;
		$result = mssql_query($sql, $this->db_resource);
		if ( ! $result )
			return FALSE;
		$ret = array();
		while ( $row = mssql_fetch_assoc($result) ) {
			$ret[] = $row;
		}
		return $ret;
	}
}
?>