【php开源代码栏目提醒】:以下是网学会员为您推荐的php开源代码-dbo_source.php,希望本篇文章对您学习有所帮助。
<?php
/* SVN FILE: $Id: dbo_source.php 4424 2007-02-03 02:55:49Z phpnut $ */
/**
* Short description for file.
*
* 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.0.1076
* @version $Revision: 4424 $
* @modifiedby $LastChangedBy: phpnut $
* @lastmodified $Date: 2007-02-02 20:55:49 -0600 (Fri, 02 Feb 2007) $
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
* DboSource
*
* Creates DBO-descendant objects from a given db connection configuration
*
* @package cake
* @subpackage cake.cake.libs.model.datasources
*/
class DboSource extends DataSource {
/**
* Description string for this Database Data Source.
*
* @var unknown_type
*/
var $description = "Database Data Source";
/**
* Enter description here...
*
* @var unknown_type
*/
var $__bypass = false;
/**
* Enter description here...
*
* @var array
*/
var $__assocJoins = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $startQuote = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $endQuote = null;
/**
* Enter description here...
*
* @var unknown_type
*/
var $alias = 'AS ';
/**
* The set of valid SQL operations usable in a WHERE statement
*
* @var array
*/
var $__sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', 'regexp', 'similar to');
/**
* Enter description here...
*
* @var unknown_type
*/
var $goofyLimit = false;
/**
* Constructor
*/
function __construct($config = null) {
$this->debug = Configure::read() > 0;
$this->fullDebug = Configure::read() > 1;
parent::__construct($config);
return $this->connect();
}
/**
* Reconnects to database server with optional new settings
*
* @param array $config An array defining the new configuration settings
* @return boolean True on success, false on failure
*/
function reconnect($config = null) {
$this->disconnect();
if ($config != null) {
$this->config = am($this->_baseConfig, $this->config, $config);
}
return $this->connect();
}
/**
* Prepares a value, or an array of values for database queries by quoting and escaping them.
*
* @param mixed $data A value or an array of values to prepare.
* @return mixed Prepared value or array of values.
*/
function value($data, $column = null) {
if (is_array($data)) {
$out = array();
$keys = array_keys($data);
$count = count($data);
for($i = 0; $i < $count; $i++) {
$out[$keys[$i]] = $this->value($data[$keys[$i]]);
}
return $out;
} elseif (in_array($data, array('{$__cakeID__$}', '{$__cakeForeignKey__$}'), true)) {
return $data;
} else {
return null;
}
}
/**
* Caches/returns cached results for child instances
*
* @return array
*/
function listSources($data = null) {
if ($this->__sources != null) {
return $this->__sources;
}
if (Configure::read() > 0) {
$expires = "+30 seconds";
} else {
$expires = "+999 days";
}
if ($data != null) {
$data = serialize($data);
}
$filename = ConnectionManager::getSourceName($this) . '_' . $this->config['database'] . '_list';
$new = cache('models' . DS . $filename, $data, $expires);
if ($new != null) {
$new = unserialize($new);
$this->__sources = $new;
}
return $new;
}
/**
* Convenience method for DboSource::listSources().
*
* @return array
*/
function sources() {
$return = array_map('strtolower', $this->listSources());
return $return;
}
/**
* SQL Query abstraction
*
* @return resource Result resource identifier
*/
function query() {
$args = func_get_args();
$fields = null;
$order = null;
$limit = null;
$page = null;
$recursive = null;
if (count($args) == 1) {
return $this->fetchAll($args[0]);
} elseif (count($args) > 1 && (strpos(low($args[0]), 'findby') === 0 || strpos(low($args[0]), 'findallby') === 0)) {
$params = $args[1];
if (strpos(strtolower($args[0]), 'findby') === 0) {
$all = false;
$field = Inflector::underscore(preg_replace('/findBy/i', '', $args[0]));
} else {
$all = true;
$field = Inflector::un