<?php
/*-
 * Copyright (c) 2008 Fredrik Lindberg - http://www.shapeshifter.se
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/*
 * db_mssql.inc
 *
 * Database class for mssql-connectivity
 */

require_once('db/iface.inc');

class 
MSSQLConnector extends SQLConnector
{
    private 
$m_dbHandle;
    private 
$m_Result;

    
/*
     * Connect function, also selects correct database
     * Returns 1 upon success, otherwise 0
     */
    
function connect($address$account$pwd$name)
    {
        
$this->m_dbHandle = @mssql_connect($address$account$pwd);

        if (
$this->m_dbHandle != 0) {
            if (
mssql_select_db($name$this->m_dbHandle)) {
                return 
1;
            }
            else {
                return 
0;
            }
        }
        else {
            return 
0;
        }
    }

    
/*
     * Disconnect function
     * Returns 1 upon success, otherwise 0
     */    
    
function disconnect()
    {
        if (@
mssql_close($this->m_dbHandle) != 0) {
            return 
1;
        }
        else {
            return 
0;
        }
    }

    
/*
     * Does a mysql-query, returns 1 upon sucess otherwise 0
     */    
    
function query($query)
    {
        
$this->m_Result mssql_query($query$this->m_dbHandle);

        if (
$this->m_Result != 0) {
            return 
1;
        }
        else {
            return 
0;
        }
    }

    
/*
     * Fetches an array row
     */    
    
function fetchRow()
    {
        return 
mssql_fetch_array($this->m_Result);
    }

    function 
fetchAll()
    {
        while (
$row mssql_fetch_array($this->m_Result)) {
            
$a_rs[] = $row;
        }
        
mssql_free_result($this->m_Result);
        return 
$a_rs;
    }
    
    
/*
     * Get number of rows
     */
    
function getNumRows()
    {
        return 
mssql_num_rows($this->m_Result);
    }

    
/*
     * Free resources allocated by a query
     */    
    
function freeResult()
    {
        
mssql_free_result($this->m_Result);
    }

    
/*
     * Get errorstring
     */
    
function getError()
    {
        return 
mysql_error($this->m_dbHandle);
    }
}        

?>