Update to CodeIgniter 2.1.0

This commit is contained in:
Karsten Heiken
2011-12-04 14:24:27 +01:00
parent fde35df5bd
commit 79c236dc49
149 changed files with 4384 additions and 590 deletions

View File

@@ -0,0 +1,41 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Enable/Disable Migrations
|--------------------------------------------------------------------------
|
| Migrations are disabled by default but should be enabled
| whenever you intend to do a schema migration.
|
*/
$config['migration_enabled'] = FALSE;
/*
|--------------------------------------------------------------------------
| Migrations version
|--------------------------------------------------------------------------
|
| This is used to set migration version that the file system should be on.
| If you run $this->migration->latest() this is the version that schema will
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 0;
/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
$config['migration_path'] = APPPATH . 'migrations/';
/* End of file migration.php */
/* Location: ./application/config/migration.php */

188
application/config/mimes.php Executable file → Normal file
View File

@@ -1,4 +1,4 @@
<?php defined('BASEPATH') || exit('No direct script access allowed');
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| MIME TYPES
@@ -8,100 +8,98 @@
|
*/
$mimes = array(
'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
'bin' => 'application/macbinary',
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => array('application/octet-stream', 'application/x-msdownload'),
'class' => 'application/octet-stream',
'psd' => 'application/x-photoshop',
'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => array('application/pdf', 'application/x-download'),
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'php' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'png' => array('image/png', 'image/x-png'),
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'shtml' => 'text/html',
'txt' => 'text/plain',
'text' => 'text/plain',
'log' => array('text/plain', 'text/x-log'),
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
'json' => array('application/json', 'text/json'),
'obj' => 'text/plain',
);
$mimes = array( 'hqx' => 'application/mac-binhex40',
'cpt' => 'application/mac-compactpro',
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel'),
'bin' => 'application/macbinary',
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => array('application/octet-stream', 'application/x-msdownload'),
'class' => 'application/octet-stream',
'psd' => 'application/x-photoshop',
'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => array('application/pdf', 'application/x-download'),
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'),
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'php' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'),
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
'bmp' => array('image/bmp', 'image/x-windows-bmp'),
'gif' => 'image/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'png' => array('image/png', 'image/x-png'),
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'shtml' => 'text/html',
'txt' => 'text/plain',
'text' => 'text/plain',
'log' => array('text/plain', 'text/x-log'),
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
'movie' => 'video/x-sgi-movie',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
'json' => array('application/json', 'text/json')
);
/* End of file mimes.php */

View File

@@ -29,6 +29,11 @@
*/
class CI_Benchmark {
/**
* List of all benchmark markers and when they were added
*
* @var array
*/
var $marker = array();
// --------------------------------------------------------------------

View File

@@ -27,17 +27,19 @@
* @link http://codeigniter.com/user_guide/
*/
/*
* ------------------------------------------------------
* Define the CodeIgniter Version
* ------------------------------------------------------
/**
* CodeIgniter Version
*
* @var string
*
*/
define('CI_VERSION', '2.0.3');
define('CI_VERSION', '2.1.0');
/*
* ------------------------------------------------------
* Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
* ------------------------------------------------------
/**
* CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
*
* @var boolean
*
*/
define('CI_CORE', FALSE);
@@ -267,7 +269,25 @@
OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
)
{
show_404("{$class}/{$method}");
if ( ! empty($RTR->routes['404_override']))
{
$x = explode('/', $RTR->routes['404_override']);
$class = $x[0];
$method = (isset($x[1]) ? $x[1] : 'index');
if ( ! class_exists($class))
{
if ( ! file_exists(APPPATH.'controllers/'.$class.'.php'))
{
show_404("{$class}/{$method}");
}
include_once(APPPATH.'controllers/'.$class.'.php');
}
}
else
{
show_404("{$class}/{$method}");
}
}
/*

30
system/core/Common.php Executable file → Normal file
View File

@@ -132,9 +132,9 @@ if ( ! function_exists('load_class'))
$name = FALSE;
// Look for the class first in the native system/libraries folder
// thenin the local application/libraries folder
foreach (array(BASEPATH, APPPATH) as $path)
// Look for the class first in the local application/libraries folder
// then in the native system/libraries folder
foreach (array(APPPATH, BASEPATH) as $path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
@@ -536,5 +536,29 @@ if ( ! function_exists('remove_invisible_characters'))
}
}
// ------------------------------------------------------------------------
/**
* Returns HTML escaped variable
*
* @access public
* @param mixed
* @return mixed
*/
if ( ! function_exists('html_escape'))
{
function html_escape($var)
{
if (is_array($var))
{
return array_map('html_escape', $var);
}
else
{
return htmlspecialchars($var, ENT_QUOTES, config_item('charset'));
}
}
}
/* End of file Common.php */
/* Location: ./system/core/Common.php */

View File

@@ -28,8 +28,23 @@
*/
class CI_Config {
/**
* List of all loaded config values
*
* @var array
*/
var $config = array();
/**
* List of all loaded config files
*
* @var array
*/
var $is_loaded = array();
/**
* List of paths to search when trying to load a config file
*
* @var array
*/
var $_config_paths = array(APPPATH);
/**
@@ -251,13 +266,13 @@ class CI_Config {
return $this->slash_item('base_url').$this->item('index_page').'?'.$this->_uri_string($uri);
}
}
// -------------------------------------------------------------
/**
* Base URL
* Returns base_url [. uri_string]
*
*
* @access public
* @param string $uri
* @return string
@@ -266,12 +281,12 @@ class CI_Config {
{
return $this->slash_item('base_url').ltrim($this->_uri_string($uri),'/');
}
// -------------------------------------------------------------
/**
* Build URI string for use in Config::site_url() and Config::base_url()
*
*
* @access protected
* @param $uri
* @return string
@@ -305,7 +320,7 @@ class CI_Config {
}
// --------------------------------------------------------------------
/**
* System URL
*

2
system/core/Controller.php Executable file → Normal file
View File

@@ -48,7 +48,7 @@ class CI_Controller {
$this->load =& load_class('Loader', 'core');
$this->load->set_base_classes()->ci_autoloader();
$this->load->initialize();
log_message('debug', "Controller Class Initialized");
}

View File

@@ -30,8 +30,21 @@ class CI_Exceptions {
var $message;
var $filename;
var $line;
/**
* Nesting level of the output buffering mechanism
*
* @var int
* @access public
*/
var $ob_level;
/**
* List if available error levels
*
* @var array
* @access public
*/
var $levels = array(
E_ERROR => 'Error',
E_WARNING => 'Warning',
@@ -84,7 +97,8 @@ class CI_Exceptions {
* 404 Page Not Found Handler
*
* @access private
* @param string
* @param string the page
* @param bool log error yes/no
* @return string
*/
function show_404($page = '', $log_error = TRUE)
@@ -115,6 +129,7 @@ class CI_Exceptions {
* @param string the heading
* @param string the message
* @param string the template name
* @param int the status code
* @return string
*/
function show_error($heading, $message, $template = 'error_general', $status_code = 500)

View File

@@ -28,8 +28,23 @@
*/
class CI_Hooks {
/**
* Determines wether hooks are enabled
*
* @var bool
*/
var $enabled = FALSE;
/**
* List of all hooks set in config/hooks.php
*
* @var array
*/
var $hooks = array();
/**
* Determines wether hook is in progress, used to prevent infinte loops
*
* @var bool
*/
var $in_progress = FALSE;
/**

View File

@@ -28,15 +28,51 @@
*/
class CI_Input {
/**
* IP address of the current user
*
* @var string
*/
var $ip_address = FALSE;
/**
* user agent (web browser) being used by the current user
*
* @var string
*/
var $user_agent = FALSE;
/**
* If FALSE, then $_GET will be set to an empty array
*
* @var bool
*/
var $_allow_get_array = TRUE;
/**
* If TRUE, then newlines are standardized
*
* @var bool
*/
var $_standardize_newlines = TRUE;
var $_enable_xss = FALSE; // Set automatically based on config setting
var $_enable_csrf = FALSE; // Set automatically based on config setting
/**
* Determines whether the XSS filter is always active when GET, POST or COOKIE data is encountered
* Set automatically based on config setting
*
* @var bool
*/
var $_enable_xss = FALSE;
/**
* Enables a CSRF cookie token to be set.
* Set automatically based on config setting
*
* @var bool
*/
var $_enable_csrf = FALSE;
/**
* List of all HTTP request headers
*
* @var array
*/
protected $headers = array();
/**
* Constructor
@@ -147,7 +183,7 @@ class CI_Input {
}
return $post;
}
return $this->_fetch_from_array($_POST, $index, $xss_clean);
}
@@ -402,9 +438,9 @@ class CI_Input {
function _sanitize_globals()
{
// It would be "wrong" to unset any of these GLOBALS.
$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
$protected = array('_SERVER', '_GET', '_POST', '_FILES', '_REQUEST',
'_SESSION', '_ENV', 'GLOBALS', 'HTTP_RAW_POST_DATA',
'system_folder', 'application_folder', 'BM', 'EXT',
'system_folder', 'application_folder', 'BM', 'EXT',
'CFG', 'URI', 'RTR', 'OUT', 'IN');
// Unset globals for securiy.
@@ -512,8 +548,12 @@ class CI_Input {
return $new_array;
}
// We strip slashes if magic quotes is on to keep things consistent
if (function_exists('get_magic_quotes_gpc') AND get_magic_quotes_gpc())
/* We strip slashes if magic quotes is on to keep things consistent
NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
it will probably not exist in future versions at all.
*/
if ( ! is_php('5.4') && get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
@@ -523,7 +563,7 @@ class CI_Input {
{
$str = $this->uni->clean_string($str);
}
// Remove control characters
$str = remove_invisible_characters($str);
@@ -579,9 +619,11 @@ class CI_Input {
/**
* Request Headers
*
* In Apache, you can simply call apache_request_headers(), however for
* In Apache, you can simply call apache_request_headers(), however for
* people running other webservers the function is undefined.
*
* @param bool XSS cleaning
*
* @return array
*/
public function request_headers($xss_clean = FALSE)
@@ -609,10 +651,10 @@ class CI_Input {
{
$key = str_replace('_', ' ', strtolower($key));
$key = str_replace(' ', '-', ucwords($key));
$this->headers[$key] = $val;
}
return $this->headers;
}
@@ -633,7 +675,7 @@ class CI_Input {
{
$this->request_headers();
}
if ( ! isset($this->headers[$index]))
{
return FALSE;
@@ -644,7 +686,7 @@ class CI_Input {
return $this->security->xss_clean($this->headers[$index]);
}
return $this->headers[$index];
return $this->headers[$index];
}
// --------------------------------------------------------------------
@@ -676,7 +718,6 @@ class CI_Input {
}
}
// END Input class
/* End of file Input.php */
/* Location: ./system/core/Input.php */
/* Location: ./system/core/Input.php */

View File

@@ -26,7 +26,17 @@
*/
class CI_Lang {
/**
* List of translations
*
* @var array
*/
var $language = array();
/**
* List of loaded language files
*
* @var array
*/
var $is_loaded = array();
/**
@@ -47,6 +57,9 @@ class CI_Lang {
* @access public
* @param mixed the name of the language file to be loaded. Can be an array
* @param string the language (english, etc.)
* @param bool return loaded array of translations
* @param bool add suffix to $langfile
* @param string alternative path to look for language file
* @return mixed
*/
function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')

136
system/core/Loader.php Executable file → Normal file
View File

@@ -29,18 +29,91 @@
class CI_Loader {
// All these are set automatically. Don't mess with them.
/**
* Nesting level of the output buffering mechanism
*
* @var int
* @access protected
*/
protected $_ci_ob_level;
/**
* List of paths to load views from
*
* @var array
* @access protected
*/
protected $_ci_view_paths = array();
/**
* List of paths to load libraries from
*
* @var array
* @access protected
*/
protected $_ci_library_paths = array();
/**
* List of paths to load models from
*
* @var array
* @access protected
*/
protected $_ci_model_paths = array();
/**
* List of paths to load helpers from
*
* @var array
* @access protected
*/
protected $_ci_helper_paths = array();
/**
* List of loaded base classes
* Set by the controller class
*
* @var array
* @access protected
*/
protected $_base_classes = array(); // Set by the controller class
/**
* List of cached variables
*
* @var array
* @access protected
*/
protected $_ci_cached_vars = array();
/**
* List of loaded classes
*
* @var array
* @access protected
*/
protected $_ci_classes = array();
/**
* List of loaded files
*
* @var array
* @access protected
*/
protected $_ci_loaded_files = array();
/**
* List of loaded models
*
* @var array
* @access protected
*/
protected $_ci_models = array();
/**
* List of loaded helpers
*
* @var array
* @access protected
*/
protected $_ci_helpers = array();
protected $_ci_varmap = array('unit_test' => 'unit',
/**
* List of class name mappings
*
* @var array
* @access protected
*/
protected $_ci_varmap = array('unit_test' => 'unit',
'user_agent' => 'agent');
/**
@@ -55,24 +128,29 @@ class CI_Loader {
$this->_ci_helper_paths = array(APPPATH, BASEPATH);
$this->_ci_model_paths = array(APPPATH);
$this->_ci_view_paths = array(APPPATH.'views/' => TRUE);
log_message('debug', "Loader Class Initialized");
}
// --------------------------------------------------------------------
/**
* Set _base_classes variable
* Initialize the Loader
*
* This method is called once in CI_Controller.
*
* @param array
* @param array
* @return object
*/
public function set_base_classes()
public function initialize()
{
$this->_ci_classes = array();
$this->_ci_loaded_files = array();
$this->_ci_models = array();
$this->_base_classes =& is_loaded();
$this->_ci_autoloader();
return $this;
}
@@ -96,7 +174,7 @@ class CI_Loader {
{
return $this->_ci_classes[$class];
}
return FALSE;
}
@@ -366,6 +444,7 @@ class CI_Loader {
* the controller class and its "view" files.
*
* @param array
* @param string
* @return void
*/
public function vars($vars = array(), $val = '')
@@ -507,6 +586,8 @@ class CI_Loader {
* Loads a config file
*
* @param string
* @param bool
* @param bool
* @return void
*/
public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
@@ -535,6 +616,11 @@ class CI_Loader {
require BASEPATH.'libraries/Driver.php';
}
if ($library == '')
{
return FALSE;
}
// We can save the loader some time since Drivers will *always* be in a subfolder,
// and typically identically named to the library
if ( ! strpos($library, '/'))
@@ -553,13 +639,13 @@ class CI_Loader {
* Prepends a parent path to the library, model, helper, and config path arrays
*
* @param string
* @param boolean
* @param boolean
* @return void
*/
public function add_package_path($path, $view_cascade=TRUE)
{
$path = rtrim($path, '/').'/';
array_unshift($this->_ci_library_paths, $path);
array_unshift($this->_ci_model_paths, $path);
array_unshift($this->_ci_helper_paths, $path);
@@ -595,6 +681,7 @@ class CI_Loader {
* If no path is provided, the most recently added path is removed.
*
* @param type
* @param bool
* @return type
*/
public function remove_package_path($path = '', $remove_config_path = TRUE)
@@ -619,7 +706,7 @@ class CI_Loader {
unset($this->{$var}[$key]);
}
}
if (isset($this->_ci_view_paths[$path.'views/']))
{
unset($this->_ci_view_paths[$path.'views/']);
@@ -658,7 +745,7 @@ class CI_Loader {
{
$$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
}
$file_exists = FALSE;
// Set the path to the requested file
@@ -680,11 +767,11 @@ class CI_Loader {
$file_exists = TRUE;
break;
}
if ( ! $cascade)
{
break;
}
}
}
}
@@ -913,6 +1000,7 @@ class CI_Loader {
*
* @param string
* @param string
* @param bool
* @param string an optional object name
* @return null
*/
@@ -935,22 +1023,22 @@ class CI_Loader {
// first, global next
if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
{
include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
include($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
break;
}
elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
{
include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
include($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
break;
}
elseif (file_exists($path .'config/'.strtolower($class).'.php'))
{
include_once($path .'config/'.strtolower($class).'.php');
include($path .'config/'.strtolower($class).'.php');
break;
}
elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php'))
{
include_once($path .'config/'.ucfirst(strtolower($class)).'.php');
include($path .'config/'.ucfirst(strtolower($class)).'.php');
break;
}
}
@@ -1020,23 +1108,19 @@ class CI_Loader {
* The config/autoload.php file contains an array that permits sub-systems,
* libraries, and helpers to be loaded automatically.
*
* This function is public, as it's used in the CI_Controller class.
* However, there is no reason you should ever needs to use it.
*
* @param array
* @return void
*/
public function ci_autoloader()
private function _ci_autoloader()
{
if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
{
include_once(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
}
else
{
include_once(APPPATH.'config/autoload.php');
include(APPPATH.'config/autoload.php');
}
if ( ! isset($autoload))
{
@@ -1122,6 +1206,7 @@ class CI_Loader {
/**
* Get a reference to a specific library or model
*
* @param string
* @return bool
*/
protected function &_ci_get_component($component)
@@ -1138,6 +1223,7 @@ class CI_Loader {
* This function preps the name of various items to make loading them more reliable.
*
* @param mixed
* @param string
* @return array
*/
protected function _ci_prep_filename($filename, $extension)

View File

@@ -42,6 +42,7 @@ class CI_Model {
* Allows models to access CI's loaded classes using the same
* syntax as controllers.
*
* @param string
* @access private
*/
function __get($key)

View File

@@ -28,15 +28,67 @@
*/
class CI_Output {
/**
* Current output string
*
* @var string
* @access protected
*/
protected $final_output;
/**
* Cache expiration time
*
* @var int
* @access protected
*/
protected $cache_expiration = 0;
/**
* List of server headers
*
* @var array
* @access protected
*/
protected $headers = array();
protected $mime_types = array();
/**
* List of mime types
*
* @var array
* @access protected
*/
protected $mime_types = array();
/**
* Determines wether profiler is enabled
*
* @var book
* @access protected
*/
protected $enable_profiler = FALSE;
/**
* Determines if output compression is enabled
*
* @var bool
* @access protected
*/
protected $_zlib_oc = FALSE;
/**
* List of profiler sections
*
* @var array
* @access protected
*/
protected $_profiler_sections = array();
protected $parse_exec_vars = TRUE; // whether or not to parse variables like {elapsed_time} and {memory_usage}
/**
* Whether or not to parse variables like {elapsed_time} and {memory_usage}
*
* @var bool
* @access protected
*/
protected $parse_exec_vars = TRUE;
/**
* Constructor
*
*/
function __construct()
{
$this->_zlib_oc = @ini_get('zlib.output_compression');
@@ -127,6 +179,7 @@ class CI_Output {
*
* @access public
* @param string
* @param bool
* @return void
*/
function set_header($header, $replace = TRUE)
@@ -265,6 +318,7 @@ class CI_Output {
* benchmark timer so the page rendering speed and memory usage can be shown.
*
* @access public
* @param string
* @return mixed
*/
function _display($output = '')
@@ -401,6 +455,7 @@ class CI_Output {
* Write a Cache File
*
* @access public
* @param string
* @return void
*/
function _write_cache($output)
@@ -452,6 +507,8 @@ class CI_Output {
* Update/serve a cached file
*
* @access public
* @param object config class
* @param object uri class
* @return void
*/
function _display_cache(&$CFG, &$URI)

View File

@@ -28,12 +28,54 @@
*/
class CI_Router {
/**
* Config class
*
* @var object
* @access public
*/
var $config;
/**
* List of routes
*
* @var array
* @access public
*/
var $routes = array();
/**
* List of error routes
*
* @var array
* @access public
*/
var $error_routes = array();
/**
* Current class name
*
* @var string
* @access public
*/
var $class = '';
/**
* Current method name
*
* @var string
* @access public
*/
var $method = 'index';
/**
* Sub-directory that contains the requested controller class
*
* @var string
* @access public
*/
var $directory = '';
/**
* Default controller (and method if specific)
*
* @var string
* @access public
*/
var $default_controller;
/**
@@ -95,7 +137,7 @@ class CI_Router {
{
include(APPPATH.'config/routes.php');
}
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);
@@ -244,7 +286,20 @@ class CI_Router {
// Does the requested controller exist in the sub-folder?
if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php'))
{
show_404($this->fetch_directory().$segments[0]);
if ( ! empty($this->routes['404_override']))
{
$x = explode('/', $this->routes['404_override']);
$this->set_directory('');
$this->set_class($x[0]);
$this->set_method(isset($x[1]) ? $x[1] : 'index');
return $x;
}
else
{
show_404($this->fetch_directory().$segments[0]);
}
}
}
else

View File

@@ -25,14 +25,49 @@
* @link http://codeigniter.com/user_guide/libraries/security.html
*/
class CI_Security {
protected $_xss_hash = '';
protected $_csrf_hash = '';
protected $_csrf_expire = 7200; // Two hours (in seconds)
protected $_csrf_token_name = 'ci_csrf_token';
protected $_csrf_cookie_name = 'ci_csrf_token';
/* never allowed, string replacement */
/**
* Random Hash for protecting URLs
*
* @var string
* @access protected
*/
protected $_xss_hash = '';
/**
* Random Hash for Cross Site Request Forgery Protection Cookie
*
* @var string
* @access protected
*/
protected $_csrf_hash = '';
/**
* Expiration time for Cross Site Request Forgery Protection Cookie
* Defaults to two hours (in seconds)
*
* @var int
* @access protected
*/
protected $_csrf_expire = 7200;
/**
* Token name for Cross Site Request Forgery Protection Cookie
*
* @var string
* @access protected
*/
protected $_csrf_token_name = 'ci_csrf_token';
/**
* Cookie name for Cross Site Request Forgery Protection Cookie
*
* @var string
* @access protected
*/
protected $_csrf_cookie_name = 'ci_csrf_token';
/**
* List of never allowed strings
*
* @var array
* @access protected
*/
protected $_never_allowed_str = array(
'document.cookie' => '[removed]',
'document.write' => '[removed]',
@@ -42,17 +77,24 @@ class CI_Security {
'-moz-binding' => '[removed]',
'<!--' => '&lt;!--',
'-->' => '--&gt;',
'<![CDATA[' => '&lt;![CDATA['
'<![CDATA[' => '&lt;![CDATA[',
'<comment>' => '&lt;comment&gt;'
);
/* never allowed, regex replacement */
/**
* List of never allowed regex replacement
*
* @var array
* @access protected
*/
protected $_never_allowed_regex = array(
"javascript\s*:" => '[removed]',
"expression\s*(\(|&\#40;)" => '[removed]', // CSS and IE
"vbscript\s*:" => '[removed]', // IE, surprise!
"Redirect\s+302" => '[removed]'
);
/**
* Constructor
*/
@@ -95,7 +137,7 @@ class CI_Security {
}
// Do the tokens exist in both the _POST and _COOKIE arrays?
if ( ! isset($_POST[$this->_csrf_token_name]) OR
if ( ! isset($_POST[$this->_csrf_token_name]) OR
! isset($_COOKIE[$this->_csrf_cookie_name]))
{
$this->csrf_show_error();
@@ -107,7 +149,7 @@ class CI_Security {
$this->csrf_show_error();
}
// We kill this since we're done and we don't want to
// We kill this since we're done and we don't want to
// polute the _POST array
unset($_POST[$this->_csrf_token_name]);
@@ -117,7 +159,7 @@ class CI_Security {
$this->csrf_set_cookie();
log_message('debug', "CSRF token verified ");
return $this;
}
@@ -146,7 +188,7 @@ class CI_Security {
setcookie($this->_csrf_cookie_name, $this->_csrf_hash, $expire, config_item('cookie_path'), config_item('cookie_domain'), $secure_cookie);
log_message('debug', "CRSF cookie Set");
return $this;
}
@@ -165,9 +207,9 @@ class CI_Security {
// --------------------------------------------------------------------
/**
* Get CSRF Hash
* Get CSRF Hash
*
* Getter Method
* Getter Method
*
* @return string self::_csrf_hash
*/
@@ -215,6 +257,7 @@ class CI_Security {
* http://ha.ckers.org/xss.html
*
* @param mixed string or array
* @param bool
* @return string
*/
public function xss_clean($str, $is_image = FALSE)
@@ -263,7 +306,7 @@ class CI_Security {
*/
$str = preg_replace_callback("/[a-z]+=([\'\"]).*?\\1/si", array($this, '_convert_attribute'), $str);
$str = preg_replace_callback("/<\w+.*?(?=>|<|$)/si", array($this, '_decode_entity'), $str);
/*
@@ -276,7 +319,7 @@ class CI_Security {
*
* This prevents strings like this: ja vascript
* NOTE: we deal with spaces between characters later.
* NOTE: preg_replace was found to be amazingly slow here on
* NOTE: preg_replace was found to be amazingly slow here on
* large blocks of data, so we use str_replace.
*/
@@ -304,8 +347,8 @@ class CI_Security {
*/
if ($is_image === TRUE)
{
// Images have a tendency to have the PHP short opening and
// closing tags every so often so we skip those and only
// Images have a tendency to have the PHP short opening and
// closing tags every so often so we skip those and only
// do the long opening tags.
$str = preg_replace('/<\?(php)/i', "&lt;?\\1", $str);
}
@@ -321,10 +364,10 @@ class CI_Security {
* These words are compacted back to their correct state.
*/
$words = array(
'javascript', 'expression', 'vbscript', 'script',
'javascript', 'expression', 'vbscript', 'script',
'applet', 'alert', 'document', 'write', 'cookie', 'window'
);
foreach ($words as $word)
{
$temp = '';
@@ -341,8 +384,8 @@ class CI_Security {
/*
* Remove disallowed Javascript in links or img tags
* We used to do some version comparisons and use of stripos for PHP5,
* but it is dog slow compared to these simplified non-capturing
* We used to do some version comparisons and use of stripos for PHP5,
* but it is dog slow compared to these simplified non-capturing
* preg_match(), especially if the pattern exists in the string
*/
do
@@ -405,11 +448,11 @@ class CI_Security {
/*
* Images are Handled in a Special Way
* - Essentially, we want to know that after all of the character
* conversion is done whether any unwanted, likely XSS, code was found.
* - Essentially, we want to know that after all of the character
* conversion is done whether any unwanted, likely XSS, code was found.
* If not, we return TRUE, as the image is clean.
* However, if the string post-conversion does not matched the
* string post-removal of XSS, then it fails, as there was unwanted XSS
* However, if the string post-conversion does not matched the
* string post-removal of XSS, then it fails, as there was unwanted XSS
* code found and removed/changed during processing.
*/
@@ -433,15 +476,7 @@ class CI_Security {
{
if ($this->_xss_hash == '')
{
if (phpversion() >= 4.2)
{
mt_srand();
}
else
{
mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff);
}
mt_srand();
$this->_xss_hash = md5(time() + mt_rand(0, 1999999999));
}
@@ -455,14 +490,11 @@ class CI_Security {
*
* This function is a replacement for html_entity_decode()
*
* In some versions of PHP the native function does not work
* when UTF-8 is the specified character set, so this gives us
* a work-around. More info here:
* http://bugs.php.net/bug.php?id=25670
*
* NOTE: html_entity_decode() has a bug in some PHP versions when UTF-8 is the
* character set, and the PHP developers said they were not back porting the
* fix to versions other than PHP 5.x.
* The reason we are not using html_entity_decode() by itself is because
* while it is not technically correct to leave out the semicolon
* at the end of an entity most browsers will still interpret the entity
* correctly. html_entity_decode() does not convert entities without
* semicolons, so we are left with our own little solution here. Bummer.
*
* @param string
* @param string
@@ -470,33 +502,14 @@ class CI_Security {
*/
public function entity_decode($str, $charset='UTF-8')
{
if (stristr($str, '&') === FALSE) return $str;
// The reason we are not using html_entity_decode() by itself is because
// while it is not technically correct to leave out the semicolon
// at the end of an entity most browsers will still interpret the entity
// correctly. html_entity_decode() does not convert entities without
// semicolons, so we are left with our own little solution here. Bummer.
if (function_exists('html_entity_decode') &&
(strtolower($charset) != 'utf-8'))
{
$str = html_entity_decode($str, ENT_COMPAT, $charset);
$str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str);
return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str);
}
// Numeric Entities
$str = preg_replace('~&#x(0*[0-9a-f]{2,5});{0,1}~ei', 'chr(hexdec("\\1"))', $str);
$str = preg_replace('~&#([0-9]{2,4});{0,1}~e', 'chr(\\1)', $str);
// Literal Entities - Slightly slow so we do another check
if (stristr($str, '&') === FALSE)
{
$str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES)));
return $str;
}
return $str;
$str = html_entity_decode($str, ENT_COMPAT, $charset);
$str = preg_replace('~&#x(0*[0-9a-f]{2,5})~ei', 'chr(hexdec("\\1"))', $str);
return preg_replace('~&#([0-9]{2,4})~e', 'chr(\\1)', $str);
}
// --------------------------------------------------------------------
@@ -505,6 +518,7 @@ class CI_Security {
* Filename Security
*
* @param string
* @param bool
* @return string
*/
public function sanitize_filename($str, $relative_path = FALSE)
@@ -542,7 +556,7 @@ class CI_Security {
"%3b", // ;
"%3d" // =
);
if ( ! $relative_path)
{
$bad[] = './';
@@ -570,7 +584,7 @@ class CI_Security {
}
// --------------------------------------------------------------------
/*
* Remove Evil HTML Attributes (like evenhandlers and style)
*
@@ -578,7 +592,7 @@ class CI_Security {
* - Everything up until a space
* For example, everything between the pipes:
* <a |style=document.write('hello');alert('world');| class=link>
* - Everything inside the quotes
* - Everything inside the quotes
* For example, everything between the pipes:
* <a |style="document.write('hello'); alert('world');"| class="link">
*
@@ -589,7 +603,7 @@ class CI_Security {
protected function _remove_evil_attributes($str, $is_image)
{
// All javascript event handlers (e.g. onload, onclick, onmouseover), style, and xmlns
$evil_attributes = array('on\w*', 'style', 'xmlns');
$evil_attributes = array('on\w*', 'style', 'xmlns', 'formaction');
if ($is_image === TRUE)
{
@@ -601,16 +615,36 @@ class CI_Security {
}
do {
$str = preg_replace(
"#<(/?[^><]+?)([^A-Za-z\-])(".implode('|', $evil_attributes).")(\s*=\s*)([\"][^>]*?[\"]|[\'][^>]*?[\']|[^>]*?)([\s><])([><]*)#i",
"<$1$6",
$str, -1, $count
);
$count = 0;
$attribs = array();
// find occurrences of illegal attribute strings without quotes
preg_match_all("/(".implode('|', $evil_attributes).")\s*=\s*([^\s]*)/is", $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
$attribs[] = preg_quote($attr[0], '/');
}
// find occurrences of illegal attribute strings with quotes (042 and 047 are octal quotes)
preg_match_all("/(".implode('|', $evil_attributes).")\s*=\s*(\042|\047)([^\\2]*?)(\\2)/is", $str, $matches, PREG_SET_ORDER);
foreach ($matches as $attr)
{
$attribs[] = preg_quote($attr[0], '/');
}
// replace illegal attribute strings that are inside an html tag
if (count($attribs) > 0)
{
$str = preg_replace("/<(\/?[^><]+?)([^A-Za-z\-])(".implode('|', $attribs).")([\s><])([><]*)/i", '<$1$2$4$5', $str, -1, $count);
}
} while ($count);
return $str;
}
// --------------------------------------------------------------------
/**
@@ -627,7 +661,7 @@ class CI_Security {
$str = '&lt;'.$matches[1].$matches[2].$matches[3];
// encode captured opening or closing brace to prevent recursive vectors
$str .= str_replace(array('>', '<'), array('&gt;', '&lt;'),
$str .= str_replace(array('>', '<'), array('&gt;', '&lt;'),
$matches[4]);
return $str;
@@ -649,7 +683,7 @@ class CI_Security {
protected function _js_link_removal($match)
{
$attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
return str_replace($match[1], preg_replace("#href=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
}
@@ -669,7 +703,7 @@ class CI_Security {
protected function _js_img_removal($match)
{
$attributes = $this->_filter_attributes(str_replace(array('<', '>'), '', $match[1]));
return str_replace($match[1], preg_replace("#src=.*?(alert\(|alert&\#40;|javascript\:|livescript\:|mocha\:|charset\=|window\.|document\.|\.cookie|<script|<xss|base64\s*,)#si", "", $attributes), $match[0]);
}
@@ -729,13 +763,13 @@ class CI_Security {
}
// --------------------------------------------------------------------
/**
* Validate URL entities
*
* Called by xss_clean()
*
* @param string
* @param string
* @return string
*/
protected function _validate_entities($str)
@@ -743,9 +777,9 @@ class CI_Security {
/*
* Protect GET variables in URLs
*/
// 901119URL5918AMP18930PROTECT8198
$str = preg_replace('|\&([a-z\_0-9\-]+)\=([a-z\_0-9\-]+)|i', $this->xss_hash()."\\1=\\2", $str);
/*
@@ -769,7 +803,7 @@ class CI_Security {
* Un-Protect GET variables in URLs
*/
$str = str_replace($this->xss_hash(), '&', $str);
return $str;
}
@@ -794,7 +828,7 @@ class CI_Security {
{
$str = preg_replace("#".$key."#i", $val, $str);
}
return $str;
}
@@ -809,16 +843,16 @@ class CI_Security {
{
if ($this->_csrf_hash == '')
{
// If the cookie exists we will use it's value.
// If the cookie exists we will use it's value.
// We don't necessarily want to regenerate it with
// each page load since a page could contain embedded
// each page load since a page could contain embedded
// sub-pages causing this feature to fail
if (isset($_COOKIE[$this->_csrf_cookie_name]) &&
if (isset($_COOKIE[$this->_csrf_cookie_name]) &&
$_COOKIE[$this->_csrf_cookie_name] != '')
{
return $this->_csrf_hash = $_COOKIE[$this->_csrf_cookie_name];
}
return $this->_csrf_hash = md5(uniqid(rand(), TRUE));
}

View File

@@ -28,9 +28,34 @@
*/
class CI_URI {
/**
* List of cached uri segments
*
* @var array
* @access public
*/
var $keyval = array();
/**
* Current uri string
*
* @var string
* @access public
*/
var $uri_string;
/**
* List of uri segments
*
* @var array
* @access public
*/
var $segments = array();
/**
* Re-indexed list of uri segments
* Starts at 1 instead of 0
*
* @var array
* @access public
*/
var $rsegments = array();
/**
@@ -127,6 +152,7 @@ class CI_URI {
* Set the URI String
*
* @access public
* @param string
* @return string
*/
function _set_uri_string($str)
@@ -366,6 +392,11 @@ class CI_URI {
/**
* Identical to above only it uses the re-routed segment array
*
* @access public
* @param integer the starting segment number
* @param array an array of default values
* @return array
*
*/
function ruri_to_assoc($n = 3, $default = array())
{

0
system/core/Utf8.php Executable file → Normal file
View File

0
system/core/index.html Executable file → Normal file
View File

View File

@@ -21,6 +21,8 @@
* @category Database
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/database/
* @param string
* @param bool Determines if active record should be used or not
*/
function &DB($params = '', $active_record_override = NULL)
{
@@ -35,7 +37,7 @@ function &DB($params = '', $active_record_override = NULL)
show_error('The configuration file database.php does not exist.');
}
}
include($file_path);
if ( ! isset($db) OR count($db) == 0)

6
system/database/DB_active_rec.php Executable file → Normal file
View File

@@ -870,11 +870,11 @@ class CI_DB_active_record extends CI_DB_driver {
*/
public function limit($value, $offset = '')
{
$this->ar_limit = $value;
$this->ar_limit = (int) $value;
if ($offset != '')
{
$this->ar_offset = $offset;
$this->ar_offset = (int) $offset;
}
return $this;
@@ -1322,7 +1322,7 @@ class CI_DB_active_record extends CI_DB_driver {
{
if ($this->db_debug)
{
return $this->display_error('db_myst_use_index');
return $this->display_error('db_must_use_index');
}
return FALSE;

2
system/database/DB_cache.php Executable file → Normal file
View File

@@ -33,7 +33,7 @@ class CI_DB_Cache {
* Grabs the CI super object instance so we can access it.
*
*/
function CI_DB_Cache(&$db)
function __construct(&$db)
{
// Assign the main CI object to $this->CI
// and load the file helper since we use it a lot

6
system/database/DB_driver.php Executable file → Normal file
View File

@@ -78,7 +78,7 @@ class CI_DB_driver {
*
* @param array
*/
function CI_DB_driver($params)
function __construct($params)
{
if (is_array($params))
{
@@ -218,7 +218,7 @@ class CI_DB_driver {
// Some DBs have functions that return the version, and don't run special
// SQL queries per se. In these instances, just return the result.
$driver_version_exceptions = array('oci8', 'sqlite');
$driver_version_exceptions = array('oci8', 'sqlite', 'cubrid');
if (in_array($this->dbdriver, $driver_version_exceptions))
{
@@ -1387,4 +1387,4 @@ class CI_DB_driver {
/* End of file DB_driver.php */
/* Location: ./system/database/DB_driver.php */
/* Location: ./system/database/DB_driver.php */

4
system/database/DB_forge.php Executable file → Normal file
View File

@@ -35,7 +35,7 @@ class CI_DB_forge {
* Grabs the CI super object instance so we can access it.
*
*/
function CI_DB_forge()
function __construct()
{
// Assign the main database object to $this->db
$CI =& get_instance();
@@ -234,7 +234,7 @@ class CI_DB_forge {
show_error('A table name is required for that operation.');
}
$sql = $this->_rename_table($table_name, $new_table_name);
$sql = $this->_rename_table($this->db->dbprefix.$table_name, $this->db->dbprefix.$new_table_name);
return $this->db->query($sql);
}

46
system/database/DB_result.php Executable file → Normal file
View File

@@ -45,7 +45,7 @@ class CI_DB_result {
* @param string can be "object" or "array"
* @return mixed either a result object or array
*/
function result($type = 'object')
public function result($type = 'object')
{
if ($type == 'array') return $this->result_array();
else if ($type == 'object') return $this->result_object();
@@ -60,7 +60,7 @@ class CI_DB_result {
* @param class_name A string that represents the type of object you want back
* @return array of objects
*/
function custom_result_object($class_name)
public function custom_result_object($class_name)
{
if (array_key_exists($class_name, $this->custom_result_object))
{
@@ -79,12 +79,12 @@ class CI_DB_result {
while ($row = $this->_fetch_object())
{
$object = new $class_name();
foreach ($row as $key => $value)
{
$object->$key = $value;
}
$result_object[] = $object;
}
@@ -100,7 +100,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function result_object()
public function result_object()
{
if (count($this->result_object) > 0)
{
@@ -132,7 +132,7 @@ class CI_DB_result {
* @access public
* @return array
*/
function result_array()
public function result_array()
{
if (count($this->result_array) > 0)
{
@@ -166,7 +166,7 @@ class CI_DB_result {
* @param string can be "object" or "array"
* @return mixed either a result object or array
*/
function row($n = 0, $type = 'object')
public function row($n = 0, $type = 'object')
{
if ( ! is_numeric($n))
{
@@ -198,7 +198,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function set_row($key, $value = NULL)
public function set_row($key, $value = NULL)
{
// We cache the row data for subsequent uses
if ( ! is_array($this->row_data))
@@ -230,7 +230,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function custom_row_object($n, $type)
public function custom_row_object($n, $type)
{
$result = $this->custom_result_object($type);
@@ -253,7 +253,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function row_object($n = 0)
public function row_object($n = 0)
{
$result = $this->result_object();
@@ -278,7 +278,7 @@ class CI_DB_result {
* @access public
* @return array
*/
function row_array($n = 0)
public function row_array($n = 0)
{
$result = $this->result_array();
@@ -304,7 +304,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function first_row($type = 'object')
public function first_row($type = 'object')
{
$result = $this->result($type);
@@ -323,7 +323,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function last_row($type = 'object')
public function last_row($type = 'object')
{
$result = $this->result($type);
@@ -342,7 +342,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function next_row($type = 'object')
public function next_row($type = 'object')
{
$result = $this->result($type);
@@ -367,7 +367,7 @@ class CI_DB_result {
* @access public
* @return object
*/
function previous_row($type = 'object')
public function previous_row($type = 'object')
{
$result = $this->result($type);
@@ -394,14 +394,14 @@ class CI_DB_result {
* operational due to the unavailability of the database resource IDs with
* cached results.
*/
function num_rows() { return $this->num_rows; }
function num_fields() { return 0; }
function list_fields() { return array(); }
function field_data() { return array(); }
function free_result() { return TRUE; }
function _data_seek() { return TRUE; }
function _fetch_assoc() { return array(); }
function _fetch_object() { return array(); }
public function num_rows() { return $this->num_rows; }
public function num_fields() { return 0; }
public function list_fields() { return array(); }
public function field_data() { return array(); }
public function free_result() { return TRUE; }
protected function _data_seek() { return TRUE; }
protected function _fetch_assoc() { return array(); }
protected function _fetch_object() { return array(); }
}
// END DB_result class

2
system/database/DB_utility.php Executable file → Normal file
View File

@@ -33,7 +33,7 @@ class CI_DB_utility extends CI_DB_forge {
* Grabs the CI super object instance so we can access it.
*
*/
function CI_DB_utility()
function __construct()
{
// Assign the main database object to $this->db
$CI =& get_instance();

View File

@@ -0,0 +1,792 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author Esen Sagynov
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 2.0.2
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CUBRID Database Adapter Class
*
* Note: _DB is an extender class that the app controller
* creates dynamically based on whether the active record
* class is being used or not.
*
* @package CodeIgniter
* @subpackage Drivers
* @category Database
* @author Esen Sagynov
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_cubrid_driver extends CI_DB {
// Default CUBRID Broker port. Will be used unless user
// explicitly specifies another one.
const DEFAULT_PORT = 33000;
var $dbdriver = 'cubrid';
// The character used for escaping - no need in CUBRID
var $_escape_char = '';
// clause and character used for LIKE escape sequences - not used in CUBRID
var $_like_escape_str = '';
var $_like_escape_chr = '';
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
var $_count_string = 'SELECT COUNT(*) AS ';
var $_random_keyword = ' RAND()'; // database specific random keyword
/**
* Non-persistent database connection
*
* @access private called by the base class
* @return resource
*/
function db_connect()
{
// If no port is defined by the user, use the default value
if ($this->port == '')
{
$this->port = self::DEFAULT_PORT;
}
$conn = cubrid_connect($this->hostname, $this->port, $this->database, $this->username, $this->password);
if ($conn)
{
// Check if a user wants to run queries in dry, i.e. run the
// queries but not commit them.
if (isset($this->auto_commit) && ! $this->auto_commit)
{
cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_FALSE);
}
else
{
cubrid_set_autocommit($conn, CUBRID_AUTOCOMMIT_TRUE);
$this->auto_commit = TRUE;
}
}
return $conn;
}
// --------------------------------------------------------------------
/**
* Persistent database connection
* In CUBRID persistent DB connection is supported natively in CUBRID
* engine which can be configured in the CUBRID Broker configuration
* file by setting the CCI_PCONNECT parameter to ON. In that case, all
* connections established between the client application and the
* server will become persistent. This is calling the same
* @cubrid_connect function will establish persisten connection
* considering that the CCI_PCONNECT is ON.
*
* @access private called by the base class
* @return resource
*/
function db_pconnect()
{
return $this->db_connect();
}
// --------------------------------------------------------------------
/**
* Reconnect
*
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
* @access public
* @return void
*/
function reconnect()
{
if (cubrid_ping($this->conn_id) === FALSE)
{
$this->conn_id = FALSE;
}
}
// --------------------------------------------------------------------
/**
* Select the database
*
* @access private called by the base class
* @return resource
*/
function db_select()
{
// In CUBRID there is no need to select a database as the database
// is chosen at the connection time.
// So, to determine if the database is "selected", all we have to
// do is ping the server and return that value.
return cubrid_ping($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Set client character set
*
* @access public
* @param string
* @param string
* @return resource
*/
function db_set_charset($charset, $collation)
{
// In CUBRID, there is no need to set charset or collation.
// This is why returning true will allow the application continue
// its normal process.
return TRUE;
}
// --------------------------------------------------------------------
/**
* Version number query string
*
* @access public
* @return string
*/
function _version()
{
// To obtain the CUBRID Server version, no need to run the SQL query.
// CUBRID PHP API provides a function to determin this value.
// This is why we also need to add 'cubrid' value to the list of
// $driver_version_exceptions array in DB_driver class in
// version() function.
return cubrid_get_server_info($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Execute the query
*
* @access private called by the base class
* @param string an SQL query
* @return resource
*/
function _execute($sql)
{
$sql = $this->_prep_query($sql);
return @cubrid_query($sql, $this->conn_id);
}
// --------------------------------------------------------------------
/**
* Prep the query
*
* If needed, each database adapter can prep the query string
*
* @access private called by execute()
* @param string an SQL query
* @return string
*/
function _prep_query($sql)
{
// No need to prepare
return $sql;
}
// --------------------------------------------------------------------
/**
* Begin Transaction
*
* @access public
* @return bool
*/
function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
$this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
if (cubrid_get_autocommit($this->conn_id))
{
cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE);
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Commit Transaction
*
* @access public
* @return bool
*/
function trans_commit()
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
cubrid_commit($this->conn_id);
if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id))
{
cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE);
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Rollback Transaction
*
* @access public
* @return bool
*/
function trans_rollback()
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
cubrid_rollback($this->conn_id);
if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id))
{
cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE);
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Escape String
*
* @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
return $str;
}
if (function_exists('cubrid_real_escape_string') AND is_resource($this->conn_id))
{
$str = cubrid_real_escape_string($str, $this->conn_id);
}
else
{
$str = addslashes($str);
}
// escape LIKE condition wildcards
if ($like === TRUE)
{
$str = str_replace(array('%', '_'), array('\\%', '\\_'), $str);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Affected Rows
*
* @access public
* @return integer
*/
function affected_rows()
{
return @cubrid_affected_rows($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Insert ID
*
* @access public
* @return integer
*/
function insert_id()
{
return @cubrid_insert_id($this->conn_id);
}
// --------------------------------------------------------------------
/**
* "Count All" query
*
* Generates a platform-specific query string that counts all records in
* the specified table
*
* @access public
* @param string
* @return string
*/
function count_all($table = '')
{
if ($table == '')
{
return 0;
}
$query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}
// --------------------------------------------------------------------
/**
* List table query
*
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
* @param boolean
* @return string
*/
function _list_tables($prefix_limit = FALSE)
{
$sql = "SHOW TABLES";
if ($prefix_limit !== FALSE AND $this->dbprefix != '')
{
$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%'";
}
return $sql;
}
// --------------------------------------------------------------------
/**
* Show column query
*
* Generates a platform-specific query string so that the column names can be fetched
*
* @access public
* @param string the table name
* @return string
*/
function _list_columns($table = '')
{
return "SHOW COLUMNS FROM ".$this->_protect_identifiers($table, TRUE, NULL, FALSE);
}
// --------------------------------------------------------------------
/**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
*
* @access public
* @param string the table name
* @return object
*/
function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
}
// --------------------------------------------------------------------
/**
* The error message string
*
* @access private
* @return string
*/
function _error_message()
{
return cubrid_error($this->conn_id);
}
// --------------------------------------------------------------------
/**
* The error message number
*
* @access private
* @return integer
*/
function _error_number()
{
return cubrid_errno($this->conn_id);
}
// --------------------------------------------------------------------
/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @access private
* @param string
* @return string
*/
function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}
foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
}
if (strpos($item, '.') !== FALSE)
{
$str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
}
else
{
$str = $this->_escape_char.$item.$this->_escape_char;
}
// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
// --------------------------------------------------------------------
/**
* From Tables
*
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
* @access public
* @param type
* @return type
*/
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return '('.implode(', ', $tables).')';
}
// --------------------------------------------------------------------
/**
* Insert statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------
/**
* Replace statement
*
* Generates a platform-specific replace string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _replace($table, $keys, $values)
{
return "REPLACE INTO ".$table." (\"".implode('", "', $keys)."\") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------
/**
* Insert_batch statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert_batch($table, $keys, $values)
{
return "INSERT INTO ".$table." (\"".implode('", "', $keys)."\") VALUES ".implode(', ', $values);
}
// --------------------------------------------------------------------
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @param array the orderby clause
* @param array the limit clause
* @return string
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
$valstr[] = sprintf('"%s" = %s', $key, $val);
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
$sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
$sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
$sql .= $orderby.$limit;
return $sql;
}
// --------------------------------------------------------------------
/**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
*
* @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
foreach (array_keys($val) as $field)
{
if ($field != $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}
$sql = "UPDATE ".$table." SET ";
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
{
$cases .= $row."\n";
}
$cases .= 'ELSE '.$k.' END, ';
}
$sql .= substr($cases, 0, -2);
$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
return $sql;
}
// --------------------------------------------------------------------
/**
* Truncate statement
*
* Generates a platform-specific truncate string from the supplied data
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
* @access public
* @param string the table name
* @return string
*/
function _truncate($table)
{
return "TRUNCATE ".$table;
}
// --------------------------------------------------------------------
/**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
*
* @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
$conditions .= implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
$conditions .= " AND ";
}
$conditions .= implode("\n", $like);
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
return "DELETE FROM ".$table.$conditions.$limit;
}
// --------------------------------------------------------------------
/**
* Limit string
*
* Generates a platform-specific LIMIT clause
*
* @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
function _limit($sql, $limit, $offset)
{
if ($offset == 0)
{
$offset = '';
}
else
{
$offset .= ", ";
}
return $sql."LIMIT ".$offset.$limit;
}
// --------------------------------------------------------------------
/**
* Close DB Connection
*
* @access public
* @param resource
* @return void
*/
function _close($conn_id)
{
@cubrid_close($conn_id);
}
}
/* End of file cubrid_driver.php */
/* Location: ./system/database/drivers/cubrid/cubrid_driver.php */

View File

@@ -0,0 +1,288 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author Esen Sagynov
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CUBRID Forge Class
*
* @category Database
* @author Esen Sagynov
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_cubrid_forge extends CI_DB_forge {
/**
* Create database
*
* @access private
* @param string the database name
* @return bool
*/
function _create_database($name)
{
// CUBRID does not allow to create a database in SQL. The GUI tools
// have to be used for this purpose.
return FALSE;
}
// --------------------------------------------------------------------
/**
* Drop database
*
* @access private
* @param string the database name
* @return bool
*/
function _drop_database($name)
{
// CUBRID does not allow to drop a database in SQL. The GUI tools
// have to be used for this purpose.
return FALSE;
}
// --------------------------------------------------------------------
/**
* Process Fields
*
* @access private
* @param mixed the fields
* @return string
*/
function _process_fields($fields)
{
$current_field_count = 0;
$sql = '';
foreach ($fields as $field=>$attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
$sql .= "\n\t$attributes";
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
$sql .= "\n\t\"" . $this->db->_protect_identifiers($field) . "\"";
if (array_key_exists('NAME', $attributes))
{
$sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
}
if (array_key_exists('TYPE', $attributes))
{
$sql .= ' '.$attributes['TYPE'];
if (array_key_exists('CONSTRAINT', $attributes))
{
switch ($attributes['TYPE'])
{
case 'decimal':
case 'float':
case 'numeric':
$sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
break;
case 'enum': // As of version 8.4.0 CUBRID does not support
// enum data type.
break;
case 'set':
$sql .= '("'.implode('","', $attributes['CONSTRAINT']).'")';
break;
default:
$sql .= '('.$attributes['CONSTRAINT'].')';
}
}
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
{
//$sql .= ' UNSIGNED';
// As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
// Will be supported in the next release as a part of MySQL Compatibility.
}
if (array_key_exists('DEFAULT', $attributes))
{
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{
$sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
}
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
{
$sql .= ' UNIQUE';
}
}
// don't add a comma on the end of the last field
if (++$current_field_count < count($fields))
{
$sql .= ',';
}
}
return $sql;
}
// --------------------------------------------------------------------
/**
* Create Table
*
* @access private
* @param string the table name
* @param mixed the fields
* @param mixed primary key(s)
* @param mixed key(s)
* @param boolean should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
if ($if_not_exists === TRUE)
{
//$sql .= 'IF NOT EXISTS ';
// As of version 8.4.0 CUBRID does not support this SQL syntax.
}
$sql .= $this->db->_escape_identifiers($table)." (";
$sql .= $this->_process_fields($fields);
// If there is a PK defined
if (count($primary_keys) > 0)
{
$key_name = "pk_" . $table . "_" .
$this->db->_protect_identifiers(implode('_', $primary_keys));
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tCONSTRAINT " . $key_name . " PRIMARY KEY(" . implode(', ', $primary_keys) . ")";
}
if (is_array($keys) && count($keys) > 0)
{
foreach ($keys as $key)
{
if (is_array($key))
{
$key_name = $this->db->_protect_identifiers(implode('_', $key));
$key = $this->db->_protect_identifiers($key);
}
else
{
$key_name = $this->db->_protect_identifiers($key);
$key = array($key_name);
}
$sql .= ",\n\tKEY \"{$key_name}\" (" . implode(', ', $key) . ")";
}
}
$sql .= "\n);";
return $sql;
}
// --------------------------------------------------------------------
/**
* Drop Table
*
* @access private
* @return string
*/
function _drop_table($table)
{
return "DROP TABLE IF EXISTS ".$this->db->_escape_identifiers($table);
}
// --------------------------------------------------------------------
/**
* Alter table query
*
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
* @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param array fields
* @param string the field after which we should add the new field
* @return object
*/
function _alter_table($alter_type, $table, $fields, $after_field = '')
{
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
// DROP has everything it needs now.
if ($alter_type == 'DROP')
{
return $sql.$this->db->_protect_identifiers($fields);
}
$sql .= $this->_process_fields($fields);
if ($after_field != '')
{
$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
}
return $sql;
}
// --------------------------------------------------------------------
/**
* Rename a table
*
* Generates a platform-specific query so that a table can be renamed
*
* @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
function _rename_table($table_name, $new_table_name)
{
$sql = 'RENAME TABLE '.$this->db->_protect_identifiers($table_name)." AS ".$this->db->_protect_identifiers($new_table_name);
return $sql;
}
}
/* End of file cubrid_forge.php */
/* Location: ./system/database/drivers/cubrid/cubrid_forge.php */

View File

@@ -0,0 +1,202 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author Esen Sagynov
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 2.0.2
* @filesource
*/
// --------------------------------------------------------------------
/**
* CUBRID Result Class
*
* This class extends the parent result class: CI_DB_result
*
* @category Database
* @author Esen Sagynov
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_cubrid_result extends CI_DB_result {
/**
* Number of rows in the result set
*
* @access public
* @return integer
*/
function num_rows()
{
return @cubrid_num_rows($this->result_id);
}
// --------------------------------------------------------------------
/**
* Number of fields in the result set
*
* @access public
* @return integer
*/
function num_fields()
{
return @cubrid_num_fields($this->result_id);
}
// --------------------------------------------------------------------
/**
* Fetch Field Names
*
* Generates an array of column names
*
* @access public
* @return array
*/
function list_fields()
{
return cubrid_column_names($this->result_id);
}
// --------------------------------------------------------------------
/**
* Field data
*
* Generates an array of objects containing field meta-data
*
* @access public
* @return array
*/
function field_data()
{
$retval = array();
$tablePrimaryKeys = array();
while ($field = cubrid_fetch_field($this->result_id))
{
$F = new stdClass();
$F->name = $field->name;
$F->type = $field->type;
$F->default = $field->def;
$F->max_length = $field->max_length;
// At this moment primary_key property is not returned when
// cubrid_fetch_field is called. The following code will
// provide a patch for it. primary_key property will be added
// in the next release.
// TODO: later version of CUBRID will provide primary_key
// property.
// When PK is defined in CUBRID, an index is automatically
// created in the db_index system table in the form of
// pk_tblname_fieldname. So the following will count how many
// columns are there which satisfy this format.
// The query will search for exact single columns, thus
// compound PK is not supported.
$res = cubrid_query($this->conn_id,
"SELECT COUNT(*) FROM db_index WHERE class_name = '" . $field->table .
"' AND is_primary_key = 'YES' AND index_name = 'pk_" .
$field->table . "_" . $field->name . "'"
);
if ($res)
{
$row = cubrid_fetch_array($res, CUBRID_NUM);
$F->primary_key = ($row[0] > 0 ? 1 : null);
}
else
{
$F->primary_key = null;
}
if (is_resource($res))
{
cubrid_close_request($res);
$this->result_id = FALSE;
}
$retval[] = $F;
}
return $retval;
}
// --------------------------------------------------------------------
/**
* Free the result
*
* @return null
*/
function free_result()
{
if(is_resource($this->result_id) ||
get_resource_type($this->result_id) == "Unknown" &&
preg_match('/Resource id #/', strval($this->result_id)))
{
cubrid_close_request($this->result_id);
$this->result_id = FALSE;
}
}
// --------------------------------------------------------------------
/**
* Data Seek
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
* @access private
* @return array
*/
function _data_seek($n = 0)
{
return cubrid_data_seek($this->result_id, $n);
}
// --------------------------------------------------------------------
/**
* Result - associative array
*
* Returns the result set as an array
*
* @access private
* @return array
*/
function _fetch_assoc()
{
return cubrid_fetch_assoc($this->result_id);
}
// --------------------------------------------------------------------
/**
* Result - object
*
* Returns the result set as an object
*
* @access private
* @return object
*/
function _fetch_object()
{
return cubrid_fetch_object($this->result_id);
}
}
/* End of file cubrid_result.php */
/* Location: ./system/database/drivers/cubrid/cubrid_result.php */

View File

@@ -0,0 +1,108 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author Esen Sagynov
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CUBRID Utility Class
*
* @category Database
* @author Esen Sagynov
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_cubrid_utility extends CI_DB_utility {
/**
* List databases
*
* @access private
* @return array
*/
function _list_databases()
{
// CUBRID does not allow to see the list of all databases on the
// server. It is the way its architecture is designed. Every
// database is independent and isolated.
// For this reason we can return only the name of the currect
// connected database.
if ($this->conn_id)
{
return "SELECT '" . $this->database . "'";
}
else
{
return FALSE;
}
}
// --------------------------------------------------------------------
/**
* Optimize table query
*
* Generates a platform-specific query so that a table can be optimized
*
* @access private
* @param string the table name
* @return object
* @link http://www.cubrid.org/manual/840/en/Optimize%20Database
*/
function _optimize_table($table)
{
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table optimization can be performed using CUBRID Manager
// database administration tool. See the link above for more info.
return FALSE;
}
// --------------------------------------------------------------------
/**
* Repair table query
*
* Generates a platform-specific query so that a table can be repaired
*
* @access private
* @param string the table name
* @return object
* @link http://www.cubrid.org/manual/840/en/Checking%20Database%20Consistency
*/
function _repair_table($table)
{
// Not supported in CUBRID as of version 8.4.0. Database or
// table consistency can be checked using CUBRID Manager
// database administration tool. See the link above for more info.
return FALSE;
}
// --------------------------------------------------------------------
/**
* CUBRID Export
*
* @access private
* @param array Preferences
* @return mixed
*/
function _backup($params = array())
{
// No SQL based support in CUBRID as of version 8.4.0. Database or
// table backup can be performed using CUBRID Manager
// database administration tool.
return $this->db->display_error('db_unsuported_feature');
}
}
/* End of file cubrid_utility.php */
/* Location: ./system/database/drivers/cubrid/cubrid_utility.php */

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

0
system/database/drivers/index.html Executable file → Normal file
View File

0
system/database/drivers/mssql/index.html Executable file → Normal file
View File

1
system/database/drivers/mssql/mssql_driver.php Executable file → Normal file
View File

@@ -367,6 +367,7 @@ class CI_DB_mssql_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}

0
system/database/drivers/mssql/mssql_forge.php Executable file → Normal file
View File

0
system/database/drivers/mssql/mssql_result.php Executable file → Normal file
View File

0
system/database/drivers/mssql/mssql_utility.php Executable file → Normal file
View File

0
system/database/drivers/mysql/index.html Executable file → Normal file
View File

14
system/database/drivers/mysql/mysql_driver.php Executable file → Normal file
View File

@@ -54,6 +54,9 @@ class CI_DB_mysql_driver extends CI_DB {
var $_count_string = 'SELECT COUNT(*) AS ';
var $_random_keyword = ' RAND()'; // database specific random keyword
// whether SET NAMES must be used to set the character set
var $use_set_names;
/**
* Non-persistent database connection
*
@@ -132,15 +135,13 @@ class CI_DB_mysql_driver extends CI_DB {
*/
function db_set_charset($charset, $collation)
{
static $use_set_names;
if ( ! isset($use_set_names))
if ( ! isset($this->use_set_names))
{
// mysql_set_charset() requires PHP >= 5.2.3 and MySQL >= 5.0.7, use SET NAMES as fallback
$use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
$this->use_set_names = (version_compare(PHP_VERSION, '5.2.3', '>=') && version_compare(mysql_get_server_info(), '5.0.7', '>=')) ? FALSE : TRUE;
}
if ($use_set_names)
if ($this->use_set_names === TRUE)
{
return @mysql_query("SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'", $this->conn_id);
}
@@ -384,6 +385,7 @@ class CI_DB_mysql_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}
@@ -439,7 +441,7 @@ class CI_DB_mysql_driver extends CI_DB {
*/
function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
return "DESCRIBE ".$table;
}
// --------------------------------------------------------------------

0
system/database/drivers/mysql/mysql_forge.php Executable file → Normal file
View File

17
system/database/drivers/mysql/mysql_result.php Executable file → Normal file
View File

@@ -84,14 +84,19 @@ class CI_DB_mysql_result extends CI_DB_result {
function field_data()
{
$retval = array();
while ($field = mysql_fetch_field($this->result_id))
while ($field = mysql_fetch_object($this->result_id))
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
$type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
$length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
$F = new stdClass();
$F->name = $field->name;
$F->type = $field->type;
$F->default = $field->def;
$F->max_length = $field->max_length;
$F->primary_key = $field->primary_key;
$F->name = $field->Field;
$F->type = $type;
$F->default = $field->Default;
$F->max_length = $length;
$F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
$retval[] = $F;
}

2
system/database/drivers/mysql/mysql_utility.php Executable file → Normal file
View File

@@ -96,7 +96,7 @@ class CI_DB_mysql_utility extends CI_DB_utility {
}
// Get the table schema
$query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.'.$table);
$query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.`'.$table.'`');
// No result means the table name was invalid
if ($query === FALSE)

0
system/database/drivers/mysqli/index.html Executable file → Normal file
View File

33
system/database/drivers/mysqli/mysqli_driver.php Executable file → Normal file
View File

@@ -54,6 +54,9 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
var $delete_hack = TRUE;
// whether SET NAMES must be used to set the character set
var $use_set_names;
// --------------------------------------------------------------------
/**
@@ -132,15 +135,13 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
function _db_set_charset($charset, $collation)
{
static $use_set_names;
if ( ! isset($use_set_names))
if ( ! isset($this->use_set_names))
{
// mysqli_set_charset() requires MySQL >= 5.0.7, use SET NAMES as fallback
$use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE;
$this->use_set_names = (version_compare(mysqli_get_server_info($this->conn_id), '5.0.7', '>=')) ? FALSE : TRUE;
}
if ($use_set_names)
if ($this->use_set_names === TRUE)
{
return @mysqli_query($this->conn_id, "SET NAMES '".$this->escape_str($charset)."' COLLATE '".$this->escape_str($collation)."'");
}
@@ -385,6 +386,7 @@ class CI_DB_mysqli_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}
@@ -440,7 +442,7 @@ class CI_DB_mysqli_driver extends CI_DB {
*/
function _field_data($table)
{
return "SELECT * FROM ".$table." LIMIT 1";
return "DESCRIBE ".$table;
}
// --------------------------------------------------------------------
@@ -568,6 +570,25 @@ class CI_DB_mysqli_driver extends CI_DB {
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
}
// --------------------------------------------------------------------
/**
* Replace statement
*
* Generates a platform-specific replace string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _replace($table, $keys, $values)
{
return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------

0
system/database/drivers/mysqli/mysqli_forge.php Executable file → Normal file
View File

19
system/database/drivers/mysqli/mysqli_result.php Executable file → Normal file
View File

@@ -84,21 +84,26 @@ class CI_DB_mysqli_result extends CI_DB_result {
function field_data()
{
$retval = array();
while ($field = mysqli_fetch_field($this->result_id))
while ($field = mysqli_fetch_object($this->result_id))
{
preg_match('/([a-zA-Z]+)(\(\d+\))?/', $field->Type, $matches);
$type = (array_key_exists(1, $matches)) ? $matches[1] : NULL;
$length = (array_key_exists(2, $matches)) ? preg_replace('/[^\d]/', '', $matches[2]) : NULL;
$F = new stdClass();
$F->name = $field->name;
$F->type = $field->type;
$F->default = $field->def;
$F->max_length = $field->max_length;
$F->primary_key = ($field->flags & MYSQLI_PRI_KEY_FLAG) ? 1 : 0;
$F->name = $field->Field;
$F->type = $type;
$F->default = $field->Default;
$F->max_length = $length;
$F->primary_key = ( $field->Key == 'PRI' ? 1 : 0 );
$retval[] = $F;
}
return $retval;
}
// --------------------------------------------------------------------
/**

0
system/database/drivers/mysqli/mysqli_utility.php Executable file → Normal file
View File

0
system/database/drivers/oci8/index.html Executable file → Normal file
View File

161
system/database/drivers/oci8/oci8_driver.php Executable file → Normal file
View File

@@ -35,8 +35,6 @@
* This is a modification of the DB_driver class to
* permit access to oracle databases
*
* NOTE: this uses the PHP 4 oci methods
*
* @author Kelly McArdle
*
*/
@@ -77,9 +75,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
function db_connect()
public function db_connect()
{
return @ocilogon($this->username, $this->password, $this->hostname);
return @oci_connect($this->username, $this->password, $this->hostname, $this->char_set);
}
// --------------------------------------------------------------------
@@ -90,9 +88,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
function db_pconnect()
public function db_pconnect()
{
return @ociplogon($this->username, $this->password, $this->hostname);
return @oci_pconnect($this->username, $this->password, $this->hostname, $this->char_set);
}
// --------------------------------------------------------------------
@@ -106,9 +104,10 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return void
*/
function reconnect()
public function reconnect()
{
// not implemented in oracle
return;
}
// --------------------------------------------------------------------
@@ -119,8 +118,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private called by the base class
* @return resource
*/
function db_select()
public function db_select()
{
// Not in Oracle - schemas are actually usernames
return TRUE;
}
@@ -134,7 +134,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string
* @return resource
*/
function db_set_charset($charset, $collation)
public function db_set_charset($charset, $collation)
{
// @todo - add support if needed
return TRUE;
@@ -145,12 +145,12 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Version number query string
*
* @access public
* @access protected
* @return string
*/
function _version()
protected function _version()
{
return ociserverversion($this->conn_id);
return oci_server_version($this->conn_id);
}
// --------------------------------------------------------------------
@@ -158,18 +158,18 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Execute the query
*
* @access private called by the base class
* @access protected called by the base class
* @param string an SQL query
* @return resource
*/
function _execute($sql)
protected function _execute($sql)
{
// oracle must parse the query before it is run. All of the actions with
// the query are based on the statement id returned by ociparse
$this->stmt_id = FALSE;
$this->_set_stmt_id($sql);
ocisetprefetch($this->stmt_id, 1000);
return @ociexecute($this->stmt_id, $this->_commit);
oci_set_prefetch($this->stmt_id, 1000);
return @oci_execute($this->stmt_id, $this->_commit);
}
/**
@@ -179,11 +179,11 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string an SQL query
* @return none
*/
function _set_stmt_id($sql)
private function _set_stmt_id($sql)
{
if ( ! is_resource($this->stmt_id))
{
$this->stmt_id = ociparse($this->conn_id, $this->_prep_query($sql));
$this->stmt_id = oci_parse($this->conn_id, $this->_prep_query($sql));
}
}
@@ -198,7 +198,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string an SQL query
* @return string
*/
function _prep_query($sql)
private function _prep_query($sql)
{
return $sql;
}
@@ -211,9 +211,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return cursor id
*/
function get_cursor()
public function get_cursor()
{
$this->curs_id = ocinewcursor($this->conn_id);
$this->curs_id = oci_new_cursor($this->conn_id);
return $this->curs_id;
}
@@ -237,7 +237,7 @@ class CI_DB_oci8_driver extends CI_DB {
* type yes the type of the parameter
* length yes the max size of the parameter
*/
function stored_procedure($package, $procedure, $params)
public function stored_procedure($package, $procedure, $params)
{
if ($package == '' OR $procedure == '' OR ! is_array($params))
{
@@ -257,7 +257,7 @@ class CI_DB_oci8_driver extends CI_DB {
{
$sql .= $param['name'] . ",";
if (array_key_exists('type', $param) && ($param['type'] == OCI_B_CURSOR))
if (array_key_exists('type', $param) && ($param['type'] === OCI_B_CURSOR))
{
$have_cursor = TRUE;
}
@@ -278,7 +278,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access private
* @return none
*/
function _bind_params($params)
private function _bind_params($params)
{
if ( ! is_array($params) OR ! is_resource($this->stmt_id))
{
@@ -295,7 +295,7 @@ class CI_DB_oci8_driver extends CI_DB {
}
}
ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
}
}
@@ -307,7 +307,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return bool
*/
function trans_begin($test_mode = FALSE)
public function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
@@ -337,7 +337,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return bool
*/
function trans_commit()
public function trans_commit()
{
if ( ! $this->trans_enabled)
{
@@ -350,7 +350,7 @@ class CI_DB_oci8_driver extends CI_DB {
return TRUE;
}
$ret = OCIcommit($this->conn_id);
$ret = oci_commit($this->conn_id);
$this->_commit = OCI_COMMIT_ON_SUCCESS;
return $ret;
}
@@ -363,7 +363,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return bool
*/
function trans_rollback()
public function trans_rollback()
{
if ( ! $this->trans_enabled)
{
@@ -376,7 +376,7 @@ class CI_DB_oci8_driver extends CI_DB {
return TRUE;
}
$ret = OCIrollback($this->conn_id);
$ret = oci_rollback($this->conn_id);
$this->_commit = OCI_COMMIT_ON_SUCCESS;
return $ret;
}
@@ -391,7 +391,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
function escape_str($str, $like = FALSE)
public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
@@ -424,9 +424,9 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return integer
*/
function affected_rows()
public function affected_rows()
{
return @ocirowcount($this->stmt_id);
return @oci_num_rows($this->stmt_id);
}
// --------------------------------------------------------------------
@@ -437,7 +437,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @access public
* @return integer
*/
function insert_id()
public function insert_id()
{
// not supported in oracle
return $this->display_error('db_unsupported_function');
@@ -455,7 +455,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string
* @return string
*/
function count_all($table = '')
public function count_all($table = '')
{
if ($table == '')
{
@@ -470,6 +470,7 @@ class CI_DB_oci8_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}
@@ -480,11 +481,11 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
* @access protected
* @param boolean
* @return string
* @return string
*/
function _list_tables($prefix_limit = FALSE)
protected function _list_tables($prefix_limit = FALSE)
{
$sql = "SELECT TABLE_NAME FROM ALL_TABLES";
@@ -503,11 +504,11 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific query string so that the column names can be fetched
*
* @access public
* @access protected
* @param string the table name
* @return string
*/
function _list_columns($table = '')
protected function _list_columns($table = '')
{
return "SELECT COLUMN_NAME FROM all_tab_columns WHERE table_name = '$table'";
}
@@ -523,7 +524,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param string the table name
* @return object
*/
function _field_data($table)
protected function _field_data($table)
{
return "SELECT * FROM ".$table." where rownum = 1";
}
@@ -533,12 +534,13 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* The error message string
*
* @access private
* @access protected
* @return string
*/
function _error_message()
protected function _error_message()
{
$error = ocierror($this->conn_id);
// If the error was during connection, no conn_id should be passed
$error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
return $error['message'];
}
@@ -547,12 +549,13 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* The error message number
*
* @access private
* @access protected
* @return integer
*/
function _error_number()
protected function _error_number()
{
$error = ocierror($this->conn_id);
// Same as _error_message()
$error = is_resource($this->conn_id) ? oci_error($this->conn_id) : oci_error();
return $error['code'];
}
@@ -563,11 +566,11 @@ class CI_DB_oci8_driver extends CI_DB {
*
* This function escapes column and table names
*
* @access private
* @access protected
* @param string
* @return string
*/
function _escape_identifiers($item)
protected function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
@@ -606,11 +609,11 @@ class CI_DB_oci8_driver extends CI_DB {
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
* @access public
* @access protected
* @param type
* @return type
*/
function _from_tables($tables)
protected function _from_tables($tables)
{
if ( ! is_array($tables))
{
@@ -633,9 +636,37 @@ class CI_DB_oci8_driver extends CI_DB {
* @param array the insert values
* @return string
*/
function _insert($table, $keys, $values)
protected function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------
/**
* Insert_batch statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access protected
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
protected function _insert_batch($table, $keys, $values)
{
$keys = implode(', ', $keys);
$sql = "INSERT ALL\n";
for ($i = 0, $c = count($values); $i < $c; $i++)
{
$sql .= ' INTO ' . $table . ' (' . $keys . ') VALUES ' . $values[$i] . "\n";
}
$sql .= 'SELECT * FROM dual';
return $sql;
}
// --------------------------------------------------------------------
@@ -645,7 +676,7 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific update string from the supplied data
*
* @access public
* @access protected
* @param string the table name
* @param array the update data
* @param array the where clause
@@ -653,7 +684,7 @@ class CI_DB_oci8_driver extends CI_DB {
* @param array the limit clause
* @return string
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
@@ -682,11 +713,11 @@ class CI_DB_oci8_driver extends CI_DB {
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
* @access public
* @access protected
* @param string the table name
* @return string
*/
function _truncate($table)
protected function _truncate($table)
{
return "TRUNCATE TABLE ".$table;
}
@@ -698,13 +729,13 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific delete string from the supplied data
*
* @access public
* @access protected
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
function _delete($table, $where = array(), $like = array(), $limit = FALSE)
protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
@@ -732,13 +763,13 @@ class CI_DB_oci8_driver extends CI_DB {
*
* Generates a platform-specific LIMIT clause
*
* @access public
* @access protected
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
function _limit($sql, $limit, $offset)
protected function _limit($sql, $limit, $offset)
{
$limit = $offset + $limit;
$newsql = "SELECT * FROM (select inner_query.*, rownum rnum FROM ($sql) inner_query WHERE rownum < $limit)";
@@ -759,13 +790,13 @@ class CI_DB_oci8_driver extends CI_DB {
/**
* Close DB Connection
*
* @access public
* @access protected
* @param resource
* @return void
*/
function _close($conn_id)
protected function _close($conn_id)
{
@ocilogoff($conn_id);
@oci_close($conn_id);
}
@@ -774,4 +805,4 @@ class CI_DB_oci8_driver extends CI_DB {
/* End of file oci8_driver.php */
/* Location: ./system/database/drivers/oci8/oci8_driver.php */
/* Location: ./system/database/drivers/oci8/oci8_driver.php */

0
system/database/drivers/oci8/oci8_forge.php Executable file → Normal file
View File

98
system/database/drivers/oci8/oci8_result.php Executable file → Normal file
View File

@@ -40,14 +40,17 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return integer
*/
function num_rows()
public function num_rows()
{
$rowcount = count($this->result_array());
@ociexecute($this->stmt_id);
if ($this->curs_id)
if ($this->num_rows === 0 && count($this->result_array()) > 0)
{
@ociexecute($this->curs_id);
$this->num_rows = count($this->result_array());
@oci_execute($this->stmt_id);
if ($this->curs_id)
{
@oci_execute($this->curs_id);
}
}
return $rowcount;
@@ -61,9 +64,9 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return integer
*/
function num_fields()
public function num_fields()
{
$count = @ocinumcols($this->stmt_id);
$count = @oci_num_fields($this->stmt_id);
// if we used a limit we subtract it
if ($this->limit_used)
@@ -84,13 +87,12 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return array
*/
function list_fields()
public function list_fields()
{
$field_names = array();
$fieldCount = $this->num_fields();
for ($c = 1; $c <= $fieldCount; $c++)
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
{
$field_names[] = ocicolumnname($this->stmt_id, $c);
$field_names[] = oci_field_name($this->stmt_id, $c);
}
return $field_names;
}
@@ -105,16 +107,15 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return array
*/
function field_data()
public function field_data()
{
$retval = array();
$fieldCount = $this->num_fields();
for ($c = 1; $c <= $fieldCount; $c++)
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
{
$F = new stdClass();
$F->name = ocicolumnname($this->stmt_id, $c);
$F->type = ocicolumntype($this->stmt_id, $c);
$F->max_length = ocicolumnsize($this->stmt_id, $c);
$F = new stdClass();
$F->name = oci_field_name($this->stmt_id, $c);
$F->type = oci_field_type($this->stmt_id, $c);
$F->max_length = oci_field_size($this->stmt_id, $c);
$retval[] = $F;
}
@@ -129,11 +130,11 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* @return null
*/
function free_result()
public function free_result()
{
if (is_resource($this->result_id))
{
ocifreestatement($this->result_id);
oci_free_statement($this->result_id);
$this->result_id = FALSE;
}
}
@@ -145,14 +146,13 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an array
*
* @access private
* @access protected
* @return array
*/
function _fetch_assoc(&$row)
protected function _fetch_assoc()
{
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
return ocifetchinto($id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
return oci_fetch_assoc($id);
}
// --------------------------------------------------------------------
@@ -162,41 +162,13 @@ class CI_DB_oci8_result extends CI_DB_result {
*
* Returns the result set as an object
*
* @access private
* @access protected
* @return object
*/
function _fetch_object()
protected function _fetch_object()
{
$result = array();
// If PHP 5 is being used we can fetch an result object
if (function_exists('oci_fetch_object'))
{
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
return @oci_fetch_object($id);
}
// If PHP 4 is being used we have to build our own result
foreach ($this->result_array() as $key => $val)
{
$obj = new stdClass();
if (is_array($val))
{
foreach ($val as $k => $v)
{
$obj->$k = $v;
}
}
else
{
$obj->$key = $val;
}
$result[] = $obj;
}
return $result;
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
return @oci_fetch_object($id);
}
// --------------------------------------------------------------------
@@ -207,17 +179,15 @@ class CI_DB_oci8_result extends CI_DB_result {
* @access public
* @return array
*/
function result_array()
public function result_array()
{
if (count($this->result_array) > 0)
{
return $this->result_array;
}
// oracle's fetch functions do not return arrays.
// The information is returned in reference parameters
$row = NULL;
while ($this->_fetch_assoc($row))
while ($row = $this->_fetch_assoc())
{
$this->result_array[] = $row;
}
@@ -234,10 +204,10 @@ class CI_DB_oci8_result extends CI_DB_result {
* this internally before fetching results to make sure the
* result set starts at zero
*
* @access private
* @access protected
* @return array
*/
function _data_seek($n = 0)
protected function _data_seek($n = 0)
{
return FALSE; // Not needed
}
@@ -246,4 +216,4 @@ class CI_DB_oci8_result extends CI_DB_result {
/* End of file oci8_result.php */
/* Location: ./system/database/drivers/oci8/oci8_result.php */
/* Location: ./system/database/drivers/oci8/oci8_result.php */

0
system/database/drivers/oci8/oci8_utility.php Executable file → Normal file
View File

0
system/database/drivers/odbc/index.html Executable file → Normal file
View File

5
system/database/drivers/odbc/odbc_driver.php Executable file → Normal file
View File

@@ -48,9 +48,9 @@ class CI_DB_odbc_driver extends CI_DB {
var $_random_keyword;
function CI_DB_odbc_driver($params)
function __construct($params)
{
parent::CI_DB($params);
parent::__construct($params);
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
}
@@ -339,6 +339,7 @@ class CI_DB_odbc_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}

0
system/database/drivers/odbc/odbc_forge.php Executable file → Normal file
View File

0
system/database/drivers/odbc/odbc_result.php Executable file → Normal file
View File

0
system/database/drivers/odbc/odbc_utility.php Executable file → Normal file
View File

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,803 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @author EllisLab Dev Team
* @link http://codeigniter.com
* @since Version 2.1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* PDO Database Adapter Class
*
* Note: _DB is an extender class that the app controller
* creates dynamically based on whether the active record
* class is being used or not.
*
* @package CodeIgniter
* @subpackage Drivers
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_pdo_driver extends CI_DB {
var $dbdriver = 'pdo';
// the character used to excape - not necessary for PDO
var $_escape_char = '';
var $_like_escape_str;
var $_like_escape_chr;
/**
* The syntax to count rows is slightly different across different
* database engines, so this string appears in each driver and is
* used for the count_all() and count_all_results() functions.
*/
var $_count_string = "SELECT COUNT(*) AS ";
var $_random_keyword;
var $options = array();
function __construct($params)
{
parent::__construct($params);
// clause and character used for LIKE escape sequences
if (strpos($this->hostname, 'mysql') !== FALSE)
{
$this->_like_escape_str = '';
$this->_like_escape_chr = '';
//Prior to this version, the charset can't be set in the dsn
if(is_php('5.3.6'))
{
$this->hostname .= ";charset={$this->char_set}";
}
//Set the charset with the connection options
$this->options['PDO::MYSQL_ATTR_INIT_COMMAND'] = "SET NAMES {$this->char_set}";
}
else if (strpos($this->hostname, 'odbc') !== FALSE)
{
$this->_like_escape_str = " {escape '%s'} ";
$this->_like_escape_chr = '!';
}
else
{
$this->_like_escape_str = " ESCAPE '%s' ";
$this->_like_escape_chr = '!';
}
$this->hostname .= ";dbname=".$this->database;
$this->trans_enabled = FALSE;
$this->_random_keyword = ' RND('.time().')'; // database specific random keyword
}
/**
* Non-persistent database connection
*
* @access private called by the base class
* @return resource
*/
function db_connect()
{
$this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
return new PDO($this->hostname, $this->username, $this->password, $this->options);
}
// --------------------------------------------------------------------
/**
* Persistent database connection
*
* @access private called by the base class
* @return resource
*/
function db_pconnect()
{
$this->options['PDO::ATTR_ERRMODE'] = PDO::ERRMODE_SILENT;
$this->options['PDO::ATTR_PERSISTENT'] = TRUE;
return new PDO($this->hostname, $this->username, $this->password, $this->options);
}
// --------------------------------------------------------------------
/**
* Reconnect
*
* Keep / reestablish the db connection if no queries have been
* sent for a length of time exceeding the server's idle timeout
*
* @access public
* @return void
*/
function reconnect()
{
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Select the database
*
* @access private called by the base class
* @return resource
*/
function db_select()
{
// Not needed for PDO
return TRUE;
}
// --------------------------------------------------------------------
/**
* Set client character set
*
* @access public
* @param string
* @param string
* @return resource
*/
function db_set_charset($charset, $collation)
{
// @todo - add support if needed
return TRUE;
}
// --------------------------------------------------------------------
/**
* Version number query string
*
* @access public
* @return string
*/
function _version()
{
return $this->conn_id->getAttribute(PDO::ATTR_CLIENT_VERSION);
}
// --------------------------------------------------------------------
/**
* Execute the query
*
* @access private called by the base class
* @param string an SQL query
* @return object
*/
function _execute($sql)
{
$sql = $this->_prep_query($sql);
$result_id = $this->conn_id->query($sql);
if (is_object($result_id))
{
$this->affect_rows = $result_id->rowCount();
}
else
{
$this->affect_rows = 0;
}
return $result_id;
}
// --------------------------------------------------------------------
/**
* Prep the query
*
* If needed, each database adapter can prep the query string
*
* @access private called by execute()
* @param string an SQL query
* @return string
*/
function _prep_query($sql)
{
return $sql;
}
// --------------------------------------------------------------------
/**
* Begin Transaction
*
* @access public
* @return bool
*/
function trans_begin($test_mode = FALSE)
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
$this->_trans_failure = (bool) ($test_mode === TRUE);
return $this->conn_id->beginTransaction();
}
// --------------------------------------------------------------------
/**
* Commit Transaction
*
* @access public
* @return bool
*/
function trans_commit()
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
$ret = $this->conn->commit();
return $ret;
}
// --------------------------------------------------------------------
/**
* Rollback Transaction
*
* @access public
* @return bool
*/
function trans_rollback()
{
if ( ! $this->trans_enabled)
{
return TRUE;
}
// When transactions are nested we only begin/commit/rollback the outermost ones
if ($this->_trans_depth > 0)
{
return TRUE;
}
$ret = $this->conn_id->rollBack();
return $ret;
}
// --------------------------------------------------------------------
/**
* Escape String
*
* @access public
* @param string
* @param bool whether or not the string will be used in a LIKE condition
* @return string
*/
function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
return $str;
}
//Escape the string
$str = $this->conn_id->quote($str);
//If there are duplicated quotes, trim them away
if (strpos($str, "'") === 0)
{
$str = substr($str, 1, -1);
}
// escape LIKE condition wildcards
if ($like === TRUE)
{
$str = str_replace( array('%', '_', $this->_like_escape_chr),
array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
$str);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Affected Rows
*
* @access public
* @return integer
*/
function affected_rows()
{
return $this->affect_rows;
}
// --------------------------------------------------------------------
/**
* Insert ID
*
* @access public
* @return integer
*/
function insert_id($name=NULL)
{
//Convenience method for postgres insertid
if (strpos($this->hostname, 'pgsql') !== FALSE)
{
$v = $this->_version();
$table = func_num_args() > 0 ? func_get_arg(0) : NULL;
if ($table == NULL && $v >= '8.1')
{
$sql='SELECT LASTVAL() as ins_id';
}
$query = $this->query($sql);
$row = $query->row();
return $row->ins_id;
}
else
{
return $this->conn_id->lastInsertId($name);
}
}
// --------------------------------------------------------------------
/**
* "Count All" query
*
* Generates a platform-specific query string that counts all records in
* the specified database
*
* @access public
* @param string
* @return string
*/
function count_all($table = '')
{
if ($table == '')
{
return 0;
}
$query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
if ($query->num_rows() == 0)
{
return 0;
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}
// --------------------------------------------------------------------
/**
* Show table query
*
* Generates a platform-specific query string so that the table names can be fetched
*
* @access private
* @param boolean
* @return string
*/
function _list_tables($prefix_limit = FALSE)
{
$sql = "SHOW TABLES FROM `".$this->database."`";
if ($prefix_limit !== FALSE AND $this->dbprefix != '')
{
//$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
return FALSE; // not currently supported
}
return $sql;
}
// --------------------------------------------------------------------
/**
* Show column query
*
* Generates a platform-specific query string so that the column names can be fetched
*
* @access public
* @param string the table name
* @return string
*/
function _list_columns($table = '')
{
return "SHOW COLUMNS FROM ".$table;
}
// --------------------------------------------------------------------
/**
* Field data query
*
* Generates a platform-specific query so that the column data can be retrieved
*
* @access public
* @param string the table name
* @return object
*/
function _field_data($table)
{
return "SELECT TOP 1 FROM ".$table;
}
// --------------------------------------------------------------------
/**
* The error message string
*
* @access private
* @return string
*/
function _error_message()
{
$error_array = $this->conn_id->errorInfo();
return $error_array[2];
}
// --------------------------------------------------------------------
/**
* The error message number
*
* @access private
* @return integer
*/
function _error_number()
{
return $this->conn_id->errorCode();
}
// --------------------------------------------------------------------
/**
* Escape the SQL Identifiers
*
* This function escapes column and table names
*
* @access private
* @param string
* @return string
*/
function _escape_identifiers($item)
{
if ($this->_escape_char == '')
{
return $item;
}
foreach ($this->_reserved_identifiers as $id)
{
if (strpos($item, '.'.$id) !== FALSE)
{
$str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
}
if (strpos($item, '.') !== FALSE)
{
$str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
}
else
{
$str = $this->_escape_char.$item.$this->_escape_char;
}
// remove duplicates if the user already included the escape
return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
}
// --------------------------------------------------------------------
/**
* From Tables
*
* This function implicitly groups FROM tables so there is no confusion
* about operator precedence in harmony with SQL standards
*
* @access public
* @param type
* @return type
*/
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return (count($tables) == 1) ? $tables[0] : '('.implode(', ', $tables).')';
}
// --------------------------------------------------------------------
/**
* Insert statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
}
// --------------------------------------------------------------------
/**
* Insert_batch statement
*
* Generates a platform-specific insert string from the supplied data
*
* @access public
* @param string the table name
* @param array the insert keys
* @param array the insert values
* @return string
*/
function _insert_batch($table, $keys, $values)
{
return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values);
}
// --------------------------------------------------------------------
/**
* Update statement
*
* Generates a platform-specific update string from the supplied data
*
* @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @param array the orderby clause
* @param array the limit clause
* @return string
*/
function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
{
foreach ($values as $key => $val)
{
$valstr[] = $key." = ".$val;
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
$orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
$sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
$sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
$sql .= $orderby.$limit;
return $sql;
}
// --------------------------------------------------------------------
/**
* Update_Batch statement
*
* Generates a platform-specific batch update string from the supplied data
*
* @access public
* @param string the table name
* @param array the update data
* @param array the where clause
* @return string
*/
function _update_batch($table, $values, $index, $where = NULL)
{
$ids = array();
$where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : '';
foreach ($values as $key => $val)
{
$ids[] = $val[$index];
foreach (array_keys($val) as $field)
{
if ($field != $index)
{
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
}
}
}
$sql = "UPDATE ".$table." SET ";
$cases = '';
foreach ($final as $k => $v)
{
$cases .= $k.' = CASE '."\n";
foreach ($v as $row)
{
$cases .= $row."\n";
}
$cases .= 'ELSE '.$k.' END, ';
}
$sql .= substr($cases, 0, -2);
$sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')';
return $sql;
}
// --------------------------------------------------------------------
/**
* Truncate statement
*
* Generates a platform-specific truncate string from the supplied data
* If the database does not support the truncate() command
* This function maps to "DELETE FROM table"
*
* @access public
* @param string the table name
* @return string
*/
function _truncate($table)
{
return $this->_delete($table);
}
// --------------------------------------------------------------------
/**
* Delete statement
*
* Generates a platform-specific delete string from the supplied data
*
* @access public
* @param string the table name
* @param array the where clause
* @param string the limit clause
* @return string
*/
function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
$conditions = '';
if (count($where) > 0 OR count($like) > 0)
{
$conditions = "\nWHERE ";
$conditions .= implode("\n", $this->ar_where);
if (count($where) > 0 && count($like) > 0)
{
$conditions .= " AND ";
}
$conditions .= implode("\n", $like);
}
$limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
return "DELETE FROM ".$table.$conditions.$limit;
}
// --------------------------------------------------------------------
/**
* Limit string
*
* Generates a platform-specific LIMIT clause
*
* @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
function _limit($sql, $limit, $offset)
{
if (strpos($this->hostname, 'cubrid') !== FALSE || strpos($this->hostname, 'sqlite') !== FALSE)
{
if ($offset == 0)
{
$offset = '';
}
else
{
$offset .= ", ";
}
return $sql."LIMIT ".$offset.$limit;
}
else
{
$sql .= "LIMIT ".$limit;
if ($offset > 0)
{
$sql .= " OFFSET ".$offset;
}
return $sql;
}
}
// --------------------------------------------------------------------
/**
* Close DB Connection
*
* @access public
* @param resource
* @return void
*/
function _close($conn_id)
{
$this->conn_id = null;
}
}
/* End of file pdo_driver.php */
/* Location: ./system/database/drivers/pdo/pdo_driver.php */

View File

@@ -0,0 +1,266 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @author EllisLab Dev Team
* @link http://codeigniter.com
* @since Version 2.1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* PDO Forge Class
*
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/database/
*/
class CI_DB_pdo_forge extends CI_DB_forge {
/**
* Create database
*
* @access private
* @param string the database name
* @return bool
*/
function _create_database()
{
// PDO has no "create database" command since it's
// designed to connect to an existing database
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Drop database
*
* @access private
* @param string the database name
* @return bool
*/
function _drop_database($name)
{
// PDO has no "drop database" command since it's
// designed to connect to an existing database
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Create Table
*
* @access private
* @param string the table name
* @param array the fields
* @param mixed primary key(s)
* @param mixed key(s)
* @param boolean should 'IF NOT EXISTS' be added to the SQL
* @return bool
*/
function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{
$sql = 'CREATE TABLE ';
if ($if_not_exists === TRUE)
{
$sql .= 'IF NOT EXISTS ';
}
$sql .= $this->db->_escape_identifiers($table)." (";
$current_field_count = 0;
foreach ($fields as $field=>$attributes)
{
// Numeric field names aren't allowed in databases, so if the key is
// numeric, we know it was assigned by PHP and the developer manually
// entered the field information, so we'll simply add it to the list
if (is_numeric($field))
{
$sql .= "\n\t$attributes";
}
else
{
$attributes = array_change_key_case($attributes, CASE_UPPER);
$sql .= "\n\t".$this->db->_protect_identifiers($field);
$sql .= ' '.$attributes['TYPE'];
if (array_key_exists('CONSTRAINT', $attributes))
{
$sql .= '('.$attributes['CONSTRAINT'].')';
}
if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
{
$sql .= ' UNSIGNED';
}
if (array_key_exists('DEFAULT', $attributes))
{
$sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}
if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
{
$sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
}
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
{
$sql .= ' AUTO_INCREMENT';
}
}
// don't add a comma on the end of the last field
if (++$current_field_count < count($fields))
{
$sql .= ',';
}
}
if (count($primary_keys) > 0)
{
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
}
if (is_array($keys) && count($keys) > 0)
{
foreach ($keys as $key)
{
if (is_array($key))
{
$key = $this->db->_protect_identifiers($key);
}
else
{
$key = array($this->db->_protect_identifiers($key));
}
$sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
}
}
$sql .= "\n)";
return $sql;
}
// --------------------------------------------------------------------
/**
* Drop Table
*
* @access private
* @return bool
*/
function _drop_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Alter table query
*
* Generates a platform-specific query so that a table can be altered
* Called by add_column(), drop_column(), and column_alter(),
*
* @access private
* @param string the ALTER type (ADD, DROP, CHANGE)
* @param string the column name
* @param string the table name
* @param string the column definition
* @param string the default value
* @param boolean should 'NOT NULL' be added
* @param string the field after which we should add the new field
* @return object
*/
function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
{
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
// DROP has everything it needs now.
if ($alter_type == 'DROP')
{
return $sql;
}
$sql .= " $column_definition";
if ($default_value != '')
{
$sql .= " DEFAULT \"$default_value\"";
}
if ($null === NULL)
{
$sql .= ' NULL';
}
else
{
$sql .= ' NOT NULL';
}
if ($after_field != '')
{
$sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
}
return $sql;
}
// --------------------------------------------------------------------
/**
* Rename a table
*
* Generates a platform-specific query so that a table can be renamed
*
* @access private
* @param string the old table name
* @param string the new table name
* @return string
*/
function _rename_table($table_name, $new_table_name)
{
$sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
return $sql;
}
}
/* End of file pdo_forge.php */
/* Location: ./system/database/drivers/pdo/pdo_forge.php */

View File

@@ -0,0 +1,171 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @author EllisLab Dev Team
* @link http://codeigniter.com
* @since Version 2.1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* PDO Result Class
*
* This class extends the parent result class: CI_DB_result
*
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/database/
*/
class CI_DB_pdo_result extends CI_DB_result {
/**
* Number of rows in the result set
*
* @access public
* @return integer
*/
function num_rows()
{
return $this->result_id->rowCount();
}
// --------------------------------------------------------------------
/**
* Number of fields in the result set
*
* @access public
* @return integer
*/
function num_fields()
{
return $this->result_id->columnCount();
}
// --------------------------------------------------------------------
/**
* Fetch Field Names
*
* Generates an array of column names
*
* @access public
* @return array
*/
function list_fields()
{
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Field data
*
* Generates an array of objects containing field meta-data
*
* @access public
* @return array
*/
function field_data()
{
$data = array();
try
{
for($i = 0; $i < $this->num_fields(); $i++)
{
$data[] = $this->result_id->getColumnMeta($i);
}
return $data;
}
catch (Exception $e)
{
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
}
// --------------------------------------------------------------------
/**
* Free the result
*
* @return null
*/
function free_result()
{
if (is_object($this->result_id))
{
$this->result_id = FALSE;
}
}
// --------------------------------------------------------------------
/**
* Data Seek
*
* Moves the internal pointer to the desired offset. We call
* this internally before fetching results to make sure the
* result set starts at zero
*
* @access private
* @return array
*/
function _data_seek($n = 0)
{
return FALSE;
}
// --------------------------------------------------------------------
/**
* Result - associative array
*
* Returns the result set as an array
*
* @access private
* @return array
*/
function _fetch_assoc()
{
return $this->result_id->fetch(PDO::FETCH_ASSOC);
}
// --------------------------------------------------------------------
/**
* Result - object
*
* Returns the result set as an object
*
* @access private
* @return object
*/
function _fetch_object()
{
return $this->result_id->fetchObject();
}
}
/* End of file pdo_result.php */
/* Location: ./system/database/drivers/pdo/pdo_result.php */

View File

@@ -0,0 +1,103 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @author EllisLab Dev Team
* @link http://codeigniter.com
* @since Version 2.1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* PDO Utility Class
*
* @category Database
* @author EllisLab Dev Team
* @link http://codeigniter.com/database/
*/
class CI_DB_pdo_utility extends CI_DB_utility {
/**
* List databases
*
* @access private
* @return bool
*/
function _list_databases()
{
// Not sure if PDO lets you list all databases...
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Optimize table query
*
* Generates a platform-specific query so that a table can be optimized
*
* @access private
* @param string the table name
* @return object
*/
function _optimize_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* Repair table query
*
* Generates a platform-specific query so that a table can be repaired
*
* @access private
* @param string the table name
* @return object
*/
function _repair_table($table)
{
// Not a supported PDO feature
if ($this->db->db_debug)
{
return $this->db->display_error('db_unsuported_feature');
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* PDO Export
*
* @access private
* @param array Preferences
* @return mixed
*/
function _backup($params = array())
{
// Currently unsupported
return $this->db->display_error('db_unsuported_feature');
}
}
/* End of file pdo_utility.php */
/* Location: ./system/database/drivers/pdo/pdo_utility.php */

0
system/database/drivers/postgre/index.html Executable file → Normal file
View File

1
system/database/drivers/postgre/postgre_driver.php Executable file → Normal file
View File

@@ -385,6 +385,7 @@ class CI_DB_postgre_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}

0
system/database/drivers/postgre/postgre_forge.php Executable file → Normal file
View File

0
system/database/drivers/postgre/postgre_result.php Executable file → Normal file
View File

0
system/database/drivers/postgre/postgre_utility.php Executable file → Normal file
View File

0
system/database/drivers/sqlite/index.html Executable file → Normal file
View File

1
system/database/drivers/sqlite/sqlite_driver.php Executable file → Normal file
View File

@@ -354,6 +354,7 @@ class CI_DB_sqlite_driver extends CI_DB {
}
$row = $query->row();
$this->_reset_select();
return (int) $row->numrows;
}

0
system/database/drivers/sqlite/sqlite_forge.php Executable file → Normal file
View File

0
system/database/drivers/sqlite/sqlite_result.php Executable file → Normal file
View File

0
system/database/drivers/sqlite/sqlite_utility.php Executable file → Normal file
View File

0
system/database/drivers/sqlsrv/index.html Executable file → Normal file
View File

1
system/database/drivers/sqlsrv/sqlsrv_driver.php Executable file → Normal file
View File

@@ -344,6 +344,7 @@ class CI_DB_sqlsrv_driver extends CI_DB {
return '0';
$row = $query->row();
$this->_reset_select();
return $row->numrows;
}

0
system/database/drivers/sqlsrv/sqlsrv_forge.php Executable file → Normal file
View File

0
system/database/drivers/sqlsrv/sqlsrv_result.php Executable file → Normal file
View File

0
system/database/drivers/sqlsrv/sqlsrv_utility.php Executable file → Normal file
View File

0
system/database/index.html Executable file → Normal file
View File

0
system/fonts/index.html Executable file → Normal file
View File

0
system/fonts/texb.ttf Executable file → Normal file
View File

0
system/helpers/array_helper.php Executable file → Normal file
View File

0
system/helpers/captcha_helper.php Executable file → Normal file
View File

0
system/helpers/cookie_helper.php Executable file → Normal file
View File

2
system/helpers/date_helper.php Executable file → Normal file
View File

@@ -116,7 +116,7 @@ if ( ! function_exists('standard_date'))
'DATE_COOKIE' => '%l, %d-%M-%y %H:%i:%s UTC',
'DATE_ISO8601' => '%Y-%m-%dT%H:%i:%s%Q',
'DATE_RFC822' => '%D, %d %M %y %H:%i:%s %O',
'DATE_RFC850' => '%l, %d-%M-%y %H:%m:%i UTC',
'DATE_RFC850' => '%l, %d-%M-%y %H:%i:%s UTC',
'DATE_RFC1036' => '%D, %d %M %y %H:%i:%s %O',
'DATE_RFC1123' => '%D, %d %M %Y %H:%i:%s %O',
'DATE_RSS' => '%D, %d %M %Y %H:%i:%s %O',

0
system/helpers/directory_helper.php Executable file → Normal file
View File

0
system/helpers/download_helper.php Executable file → Normal file
View File

0
system/helpers/email_helper.php Executable file → Normal file
View File

0
system/helpers/file_helper.php Executable file → Normal file
View File

8
system/helpers/form_helper.php Executable file → Normal file
View File

@@ -64,8 +64,8 @@ if ( ! function_exists('form_open'))
$form .= '>';
// CSRF
if ($CI->config->item('csrf_protection') === TRUE)
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if ($CI->config->item('csrf_protection') === TRUE AND ! (strpos($action, $CI->config->site_url()) === FALSE OR strpos($form, 'method="get"')))
{
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
@@ -94,7 +94,7 @@ if ( ! function_exists('form_open'))
*/
if ( ! function_exists('form_open_multipart'))
{
function form_open_multipart($action, $attributes = array(), $hidden = array())
function form_open_multipart($action = '', $attributes = array(), $hidden = array())
{
if (is_string($attributes))
{
@@ -249,7 +249,7 @@ if ( ! function_exists('form_textarea'))
{
function form_textarea($data = '', $value = '', $extra = '')
{
$defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12');
$defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '40', 'rows' => '10');
if ( ! is_array($data) OR ! isset($data['value']))
{

0
system/helpers/html_helper.php Executable file → Normal file
View File

0
system/helpers/index.html Executable file → Normal file
View File

0
system/helpers/inflector_helper.php Executable file → Normal file
View File

0
system/helpers/language_helper.php Executable file → Normal file
View File

0
system/helpers/number_helper.php Executable file → Normal file
View File

0
system/helpers/path_helper.php Executable file → Normal file
View File

0
system/helpers/security_helper.php Executable file → Normal file
View File

0
system/helpers/smiley_helper.php Executable file → Normal file
View File

17
system/helpers/string_helper.php Executable file → Normal file
View File

@@ -242,6 +242,23 @@ if ( ! function_exists('random_string'))
// ------------------------------------------------------------------------
/**
* Add's _1 to a string or increment the ending number to allow _2, _3, etc
*
* @param string $str required
* @param string $separator What should the duplicate number be appended with
* @param string $first Which number should be used for the first dupe increment
* @return string
*/
function increment_string($str, $separator = '_', $first = 1)
{
preg_match('/(.+)'.$separator.'([0-9]+)$/', $str, $match);
return isset($match[2]) ? $match[1].$separator.($match[2] + 1) : $str.$separator.$first;
}
// ------------------------------------------------------------------------
/**
* Alternator
*

0
system/helpers/text_helper.php Executable file → Normal file
View File

0
system/helpers/typography_helper.php Executable file → Normal file
View File

Some files were not shown because too many files have changed in this diff Show More