<?php

/**
 * DBMS type
 */
/**
 * DBMS type constants
 */
include_once('config.inc.php');
include_once('classes/db/DBMSData.class.php');
include_once('classes/core/CoreObject.class.php');
include_once('classes/core/DBManipulator.class.php');
include_once('classes/core/DBManipulatorMySQL.class.php');

/**
 * @author	vinadelmar <vinadelmar@users.sourceforge.net>
 * @since	2006-02-03
 * @package	Core
 */
class DBManipulatorsManager extends CoreObject {
	/**
	 * DBMS type
	 *
	 * @var	integer
	 */
	var $dbms;

	/**
	 * DBMS manipulator object
	 *
	 * @var	object
	 */
	var $dbManipulator;

	/**
	 * Class constructor
	 *
	 * DBManipulatorsManager is used to get an instance of the correct 
	 * DBManipulatorDriver (MySQL, Postgresql, ...)
	 *
	 * @param	integer	$dbms
	 * @param	string	$host
	 * @param	string	$db
	 * @param	string	$user
	 * @param	string	$pass
	 */
	function DBManipulatorsManager($dbms, $host, $db, $user, $pass) {
    $this->debug('DBManipulatorsManager::DBManipulatorsManager, status : function invoked', 10, DBG_OPEN);
    $dbData = &new DBMSData($host, $db, $user, $pass);
		switch ($dbms) {
			case MYSQL:
				$this->dbManipulator = &new DBManipulatorMySQL($dbData);
				break;
			default:
        $this->dbManipulator = null;
        $this->debug('DBManipulatorsManager::DBManipulatorsManager, error : unknown DBMS', 1);
		}
    $this->debug('DBManipulatorsManager::DBManipulatorsManager, status : function completed', 10, DBG_CLOSE);
	}
	
	/**
	 * Return instance of DBManipulator according to the DBMS used to run easy-CMS
	 *
	 * @return	mixed	object or null if error.
	 */
	function &getDBManipulator() {
    $this->debug('DBManipulatorsManager::getDBManipulator, status : function invoked', 10, DBG_OPEN);
    $result = &$this->dbManipulator;
    $this->debug('DBManipulatorsManager::getDBManipulator, status : function completed', 10, DBG_CLOSE);
    return $result;
	}
}

?>