【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-datasource.php,希望本篇文章对您学习有所帮助。
<?php
/* SVN FILE: $Id: datasource.php 4409 2007-02-02 13:20:59Z phpnut $ */
/**
* DataSource base class
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp Cake
PHP(tm) Project
* @package cake
* @subpackage cake.cake.libs.model.datasources
* @since CakePHP(tm) v 0.10.5.1790
* @version $Revision: 4409 $
* @modifiedby $LastChangedBy: phpnut $
* @lastmodified $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* DataSource base class
*
* Long description for file
*
* @package cake
* @subpackage cake.cake.libs.model.datasources
*/
class DataSource extends Object {
/**
* Are we connected to the DataSource?
*
* @var boolean
* @access public
*/
var $connected = false;
/**
* Print debug info?
*
* @var boolean
* @access public
*/
var $debug = false;
/**
* Print full query debug info?
*
* @var boolean
* @access public
*/
var $fullDebug = false;
/**
* Error description of last query
*
* @var unknown_type
* @access public
*/
var $error = null;
/**
* String to hold how many rows were affected by the last SQL operation.
*
* @var string
* @access public
*/
var $affected = null;
/**
* Number of rows in current resultset
*
* @var int
* @access public
*/
var $numRows = null;
/**
* Time the last query took
*
* @var int
* @access public
*/
var $took = null;
/**
* Enter description here...
*
* @var array
* @access private
*/
var $_result = null;
/**
* Queries count.
*
* @var int
* @access private
*/
var $_queriesCnt = 0;
/**
* Total duration of all queries.
*
* @var unknown_type
* @access private
*/
var $_queriesTime = null;
/**
* Log of queries executed by this DataSource
*
* @var unknown_type
* @access private
*/
var $_queriesLog = array();
/**
* Maximum number of items in query log, to prevent query log taking over
* too much memory on large amounts of queries -- I we've had problems at
* >6000 queries on one system.
*
* @var int Maximum number of queries in the queries log.
* @access private
*/
var $_queriesLogMax = 200;
/**
* Caches serialzed results of executed queries
*
* @var array Maximum number of queries in the queries log.
* @access private
*/
var $_queryCache = array();
/**
* The default configuration of a specific DataSource
*
* @var array
* @access public
*/
var $_baseConfig = array();
/**
* Holds references to descriptions loaded by the DataSource
*
* @var array
* @access private
*/
var $__descriptions = array();
/**
* Holds a list of sources (tables) contained in the DataSource
*
* @var array
* @access private
*/
var $__sources = null;
/**
* A reference to the physical connection of this DataSource
*
* @var array
* @access public
*/
var $connection = null;
/**
* The DataSource configuration
*
* @var array
* @access public
*/
var $config = array();
/**
* The DataSource configuration key name
*
* @var string
* @access public
*/
var $configKeyName = null;
/**
* Whether or not this DataSource is in the middle of a transaction
*
* @var boolean
* @access public
*/
var $__transactionStarted = false;
/**
* Constructor.
*/
function __construct() {
parent::__construct();
if (func_num_args() > 0) {
$this->setConfig(func_get_arg(0));
}
}
/**
* Returns true if the DataSource supports the given interface (method)
*
* @param string $interface The name of the interface (method)
* @return boolean True on success
*/
function isInterfaceSupported($interface) {
$methods = get_class_methods(get_class($this));
$methods = strtolower(implode('|', $methods));
$methods = explode('|', $methods);
$return = in_array(strtolower($interface), $methods);
return $return;
}
/**
* Sets the configuration for the DataSource
*
* @param array $config The configuration array
* @return void
*/
function setConfig($config) {
if (is_array($this->_baseConfig)) {
$this->config = $this->_baseConfig;
foreach($config as $key => $val) {
$this->config[$key] = $val;
}
}
}
/**
* Cache the DataSource description
*
* @param string $object The name of the object (model) to cache
* @param m