Location: PHPKode > projects > web.framework > web.framework-1.0.0/web.framework/DB/Core/WebDBDriver.abstract.class.php
<?php
/**
 * Project:     web.framework: the PHP5 MVC framework
 * File:		WebDBDriver.abstract.class.php
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * You may contact the authors of web.framework by e-mail at:
 * hide@address.com
 *
 * The latest version of web.framework can be obtained from:
 * http://sourceforge.net/projects/webframework
 *
 * @link http://sourceforge.net/projects/webframework
 * @copyright 2005 Marcin Staniszczak
 * @author Marcin Staniszczak <hide@address.com>
 * @version 1.0.0
 */

/**
 * This class mut be extend by any drivers classes
 *
 * @abstract
 * @name AWebDBDriver
 * @version 1.0.0
 * @package web.framework
 * @subpackage web.db
 *
 * @author Marcin Staniszczak
 * @copyright 2005 Marcin Staniszczak
 */
abstract class AWebDBDriver {
	protected
		$blnPersistent = false,
		$strLanguage = '';

	/**
	 * The class constructor (initializing DB connection)
	 *
	 * @access public
	 * @param string messages language
	 * @param array array with connection settings -> array('hostname'=>hostname, 'db'=>db name, 'port'=>port, 'userName'=>db user name, 'password'=>db user password)
	 * @param boolean for presistant connection set true, otherwise set false
	 * @throws WD_Connection_Exception
	 */
	public function __construct($strLanguage, $arrSettings, $blnPersistent) {
		$this->strLanguage = $strLanguage;
		$this->blnPersistent = $blnPersistent;

		if (!isset($arrSettings['hostname']) || !isset($arrSettings['userName']) || !isset($arrSettings['password']) || !isset($arrSettings['db'])) {
			throw new WD_Connection_Exception(Languages::$MESSAGES[$strLanguages]['EXCEPTIONS']['WEBDB']['DRIVERS']['CONNECT_PARAMETERS']);
		}
	}

	/**
	 * Return database name
	 *
	 * @abstract
	 * @access public
	 * @return database name (np. MySQL, PostreSQL)
	 */
	abstract public function serverName();

	/**
	 * Disconnect
	 *
	 * @abstract
	 * @access public
	 */
	abstract public function disconnect();

	/**
	 * Execute SQL query
	 *
	 * @abstract
	 * @access public
	 * @param string SQL query
	 * @return AWebDBRecordSet's object
	 * @throws WD_Query_Exception
	 */
	abstract public function query($strQuery);

	/**
	 * Quote SQL query string
	 *
	 * @access public
	 * @param string query string to quote
	 * @return string quoted string
	 */
	public function quote($strValue) {
		if (!get_magic_quotes_gpc()) {
			return '\''.addslashes($strValue).'\'';
		} else {
			return '\''.$strValue.'\'';
		}
	}

	/**
	 * Begin transaction
	 *
	 * @abstract
	 * @access public
	 */
	abstract public function Begin();

	/**
	 * Commit transaction
	 *
	 * @abstract
	 * @access public
	 */
	abstract public function Commit();

	/**
	 * Rollback transaction
	 *
	 * @abstract
	 * @access public
	 */
	abstract public function Rollback();

	/**
	 * Return last generated ID
	 *
	 * @abstract
	 * @access public
	 * @param string table name
	 * @param string column name
	 * @return integer last generated ID
	 */
	abstract public function getLastID($strTable='', $strColumn='');

	/**
	 * Return one record from SQL query
	 *
	 * @abstract
	 * @access public
	 * @param string SQL query
	 * @return array one record returned from SQL query
	 */
	abstract public function selectOne($strQuery);
}

/**
 * Connection exception
 * @package web.framework
 * @subpackage exceptions
 */
class WD_Connection_Exception extends WD_Exception {}

/**
 * Query execution exception
 * @package web.framework
 * @subpackage exceptions
 */
class WD_Query_Exception extends WD_Exception {}

?>
Return current item: web.framework