Location: PHPKode > projects > Entier Studio > entierstudio/framework/mssql.datasource.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.framework
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: mssql.datasource.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefMsSQLDataSource")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefMsSQLDataSource", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . "datasource.php");
    //-------------------------------------------------------------------------
    //	Class
    /*
    *	MS SQL SERVER
    *
    */
    //
    class MsSQLDataSource extends DataSource {
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
         *
         * @param	string
         * @param	integer
         * @param	string
         * @param	string
         * @param	string
         */
        function MsSQLDataSource($hostName = "", $hostPort = 0, $userName = "", $passWord = "", $dataBase = "") {
            $this->m_protocol = "mssql";
            $this->m_hostName = $hostName;
            $this->m_hostPort = $hostPort;
            $this->m_userName = $userName;
            $this->m_passWord = $passWord;
            $this->m_dataBase = $dataBase;
        }
        //---------------------------------------------------------------------
        //	Properties
        
        /**
         *
         * overrided DataSource property
         *
         * @return	object
         *
         * @see
         */
        function getDataHandler() {
            //
            return ($this);
        }
        /**
         *
         * overrided DataSource property
         *
         * @return	string
         */
        function errorString() {
            //
            if ($this->isConnectionOpen() == false) return ("MS SQL Server connection not open");
            //
            return (@mssql_get_last_message());
        }
        /**
         *
         * overrided DataSource property
         *
         * @return	integer
         */
        function errorNumber() {
            //
            if ($this->isConnectionOpen() == false) return (CONNECTION_NOT_OPEN);
            //
            return (CONNECTION_OPEN);
        }
        //---------------------------------------------------------------------
        //	Methods
        //
        // DataSource interface
        //
        
        /**
         * overrided DataSource method
         *
         * @param	string	Database name
         * @return	boolean
         */
        function openConnection() {
            //
            $this->m_resource = @mssql_pconnect($this->m_hostName, $this->m_userName, $this->m_passWord);
            if ($this->m_resource != false) {
                //
                if (@mssql_select_db($this->m_dataBase, $this->m_resource) == true) return (true);
            }
            print $this->errorString();
            //
            $this->clearConnection();
            //
            return (false);
        }
        /**
         * overrided DataSource method
         *
         * @return	boolean
         */
        function closeConnection() {
            //
            if ($this->isConnectionOpen() == false) return (false);
            //
            if (@mssql_close($this->m_resource)) {
                $this->m_resource = false;
                return (true);
            }
            //
            return (false);
        }
        //
        // SQLDataSource interface
        //
        
        /**
         *
         * @param	resource	Query Handler
         * @return	boolean
         */
        function freeStatement($resultId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (false);
            //
            if (!is_resource($resultId)) return (NULL);
            //
            return (@mssql_free_result($resultId));
        }
        /**
         *
         * @param	object	QueryDef
         * @param	array	LimitDef
         * @return	boolean
         */
        function executeQuery($SQLQuery = "", $SQLLimit = NULL) {
            //
            if (is_array($SQLLimit)) {
                if (isset($SQLLimit[_ROWFIRST_]) && isset($SQLLimit[_ROWLIMIT_])) {
                    $SQLQuery.= (" LIMIT " . $SQLLimit[_ROWFIRST_] . ", " . $SQLLimit[_ROWLIMIT_]);
                } elseif (isset($SQLLimit[ROWNUMBER])) $SQLQuery.= (" LIMIT " . $SQLLimit[_ROWLIMIT_]);
            }
            //
            if (($this->isConnectionOpen() == false) && ($this->openConnection() == false)) return (false);
            //
            return (@mssql_query($SQLQuery, $this->m_resource));
        }
        //
        //	DataRecord interface
        //
        
        /**
         * Count affected rows
         * @param	integer	Handler
         * @return	integer
         */
        function rowsAffected($resultId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (0);
            //
            return (@mssql_rows_affected($this->m_resource));
        }
        /**
         *
         * @param	integer	Handler
         */
        function lastInsertedID($resultId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (0);
            //
            return (@mssql_insert_id($this->m_resource));
        }
        //
        //	DataResult interface
        //
        
        /**
         * Count selected rows
         * @param	integer	Handler
         * @return	integer
         */
        function rowsSelected($resultId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (0);
            //
            if (!is_resource($resultId)) return (NULL);
            //
            return (@mssql_num_rows($resultId));
        }
        /**
         *
         * @param	integer	Handler
         * @return	array
         */
        function fetchDataRow($resultId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (NULL);
            //
            if (!is_resource($resultId)) return (NULL);
            //
            return (mssql_fetch_array($resultId));
        }
        /**
         *
         * @param	integer	Handler
         * @return	array	Dataset
         */
        function fetchDataSet($resultId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (NULL);
            //
            if (!is_resource($resultId)) return (NULL);
            //
            @require_once (FRAMEWORK_DIR . "datalist.php");
            //
            $dataList = new DataList();
            while ($row = $this->fetchDataRow($resultId)) {
                $dataList->set_row_values($row);
            }
            //
            return ($dataList);
        }
        /**
         *
         * @param	integer	Handler
         * @param	integer
         * @return	boolean
         */
        function moveToCursor($resultId = 0, $cursorId = 0) {
            //
            if ($this->isConnectionOpen() == false) return (false);
            //
            if (!is_resource($resultId)) return (false);
            //
            return (@mssql_data_seek($resultId, $cursorId));
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio