Location: PHPKode > projects > Entier Studio > entierstudio/framework/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 
 * @version	   $Id: datasource.php 81 2008-01-17 23:08:21Z yannromefort $
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDataSource")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDataSource", "1");
    //
    define("CONNECTION_NOT_OPEN", "0");
    define("CONNECTION_OPEN", "1");
    //-------------------------------------------------------------------------
    //	Class
    class DataSource {
        //---------------------------------------------------------------------
        //	Attributes
        
        /**
         * connection handler
         * @var	integer
         * @see
         */
        var $m_resource = false;
        /**
         * protocol name
         * @var	string
         * @see
         */
        var $m_protocol = "";
        /**
         * host name
         * @var	string
         * @see
         */
        var $m_hostName = "";
        /**
         * host port number
         * @var	integer
         * @see
         */
        var $m_hostPort = 0;
        /**
         * user name
         * @var	string
         * @see
         */
        var $m_userName = "";
        /**
         * password
         * @var	string
         * @see
         */
        var $m_passWord = "";
        /**
         * database name
         * @var	string
         * @see
         */
        var $m_dataBase = "";
        //-------------------------------------------------------------------------
        //	Constructor
        
        /**
         * base constructor
         * @param	string
         * @param	integer
         * @param	string
         * @param	string
         * @param	string
         */
        function DataSource($hostName = "", $hostPort = 0, $userName = "", $passWord = "", $dataBase = "") {
            //
            $this->m_hostName = $hostName;
            $this->m_hostPort = $hostPort;
            $this->m_userName = $userName;
            $this->m_passWord = $passWord;
            $this->m_dataBase = $dataBase;
            //
            
        }
        //-------------------------------------------------------------------------
        //	Properties
        
        /**
         * source handler get property
         * @return integer	source handler
         */
        function getDataHandler() {
            //
            return ($this->m_resource);
        }
        /**
         *
         * @return	string
         */
        function Database() {
            //
            return ($this->m_dataBase);
        }
        /**
         *
         * @return integer	source connection
         */
        function Connection() {
            //
            return ($this->m_resource);
        }
        /**
         *
         * @return	string
         */
        function errorString() {
            return ("");
        }
        /**
         *
         * @return	integer
         */
        function errorNumber() {
            return (0);
        }
        /**
         * Hash digest function
         * @access	public
         * @param	string	$item	database item name
         * @return	string
         */
        function UniqueId($item) {
            //
            $host = $database->m_hostName;
            $port = $database->m_hostPort;
            $user = $database->m_userName;
            $pass = $database->m_passWord;
            $base = $database->m_dataBase;
            //
            return (@md5($host . $port . $user . $pass . $base . Item));
        }
        /**
         * resource locator builder
         * @param	string	$item	database item name
         * @return	string
         */
        function URLocator($node = "") {
            //
            if (empty($this->m_dataBase) && !empty($node)) return ("");
            //
            $prot = $this->m_protocol;
            $host = $this->m_hostName;
            $port = $this->m_hostPort;
            $user = $this->m_userName;
            $pass = $this->m_passWord;
            $base = $this->m_dataBase;
            //
            $user = (empty($user) ? "" : (empty($pass) ? $user : $user . ":" . $pass . "@"));
            $port = (empty($port) ? "" : ":" . $port);
            $base = (empty($base) ? "" : "/" . $base . "/");
            //
            return ($prot . "://" . $user . $pass . $host . $port . $base . $node);
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         * @access	public
         * @return	boolean
         */
        function isConnectionOpen() {
            //
            return (false !== $this->m_resource);
        }
        /**
         * @access	public
         * @return	boolean
         */
        function clearConnection() {
            //
            if ($this->isConnectionOpen() == true) return ($this->closeConnection());
            //
            return (true);
        }
        //
        // DataSource interface
        //
        
        /**
         * @access	public
         * @param	string		$database
         * @return	boolean
         */
        function openConnection($database = "") {
            //
            return (false);
        }
        /**
         * @access	public
         * @return	boolean
         */
        function closeConnection() {
            //
            return (false);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio