diff options
Diffstat (limited to 'system/database/DB_result.php')
-rw-r--r-- | system/database/DB_result.php | 143 |
1 files changed, 61 insertions, 82 deletions
diff --git a/system/database/DB_result.php b/system/database/DB_result.php index 0c4e78105..730443222 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -1,20 +1,30 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource */ -// ------------------------------------------------------------------------ - /** * Database Result Class * @@ -23,32 +33,30 @@ * class for the specific database will extend and instantiate it. * * @category Database - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/database/ */ class CI_DB_result { - var $conn_id = NULL; - var $result_id = NULL; - var $result_array = array(); - var $result_object = array(); - var $custom_result_object = array(); - var $current_row = 0; - var $num_rows = 0; - var $row_data = NULL; - + public $conn_id = NULL; + public $result_id = NULL; + public $result_array = array(); + public $result_object = array(); + public $custom_result_object = array(); + public $current_row = 0; + public $num_rows = 0; + public $row_data = NULL; /** * Query result. Acts as a wrapper function for the following functions. * - * @access public * @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(); + if ($type === 'array') return $this->result_array(); + elseif ($type === 'object') return $this->result_object(); else return $this->custom_result_object($type); } @@ -57,10 +65,10 @@ class CI_DB_result { /** * Custom query result. * - * @param class_name A string that represents the type of object you want back - * @return array of objects + * @param string 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 +87,11 @@ class CI_DB_result { while ($row = $this->_fetch_object()) { $object = new $class_name(); - foreach ($row as $key => $value) { $object->$key = $value; } - + $result_object[] = $object; } @@ -97,10 +104,9 @@ class CI_DB_result { /** * Query result. "object" version. * - * @access public * @return object */ - function result_object() + public function result_object() { if (count($this->result_object) > 0) { @@ -129,10 +135,9 @@ class CI_DB_result { /** * Query result. "array" version. * - * @access public * @return array */ - function result_array() + public function result_array() { if (count($this->result_array) > 0) { @@ -161,12 +166,11 @@ class CI_DB_result { /** * Query result. Acts as a wrapper function for the following functions. * - * @access public * @param string * @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)) { @@ -185,8 +189,8 @@ class CI_DB_result { $n = 0; } - if ($type == 'object') return $this->row_object($n); - else if ($type == 'array') return $this->row_array($n); + if ($type === 'object') return $this->row_object($n); + elseif ($type === 'array') return $this->row_array($n); else return $this->custom_row_object($n, $type); } @@ -195,10 +199,9 @@ class CI_DB_result { /** * Assigns an item into a particular column slot * - * @access public - * @return object + * @return void */ - 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)) @@ -212,7 +215,6 @@ class CI_DB_result { { $this->row_data[$k] = $v; } - return; } @@ -227,14 +229,12 @@ class CI_DB_result { /** * Returns a single result row - custom object version * - * @access public * @return object */ - function custom_row_object($n, $type) + public function custom_row_object($n, $type) { $result = $this->custom_result_object($type); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -250,14 +250,12 @@ class CI_DB_result { /** * Returns a single result row - object version * - * @access public * @return object */ - function row_object($n = 0) + public function row_object($n = 0) { $result = $this->result_object(); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -275,14 +273,12 @@ class CI_DB_result { /** * Returns a single result row - array version * - * @access public * @return array */ - function row_array($n = 0) + public function row_array($n = 0) { $result = $this->result_array(); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -301,18 +297,12 @@ class CI_DB_result { /** * Returns the "first" row * - * @access public * @return object */ - function first_row($type = 'object') + public function first_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[0]; + return (count($result) === 0) ? $result : $result[0]; } // -------------------------------------------------------------------- @@ -320,18 +310,12 @@ class CI_DB_result { /** * Returns the "last" row * - * @access public * @return object */ - function last_row($type = 'object') + public function last_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) - { - return $result; - } - return $result[count($result) -1]; + return (count($result) === 0) ? $result : $result[count($result) - 1]; } // -------------------------------------------------------------------- @@ -339,14 +323,12 @@ class CI_DB_result { /** * Returns the "next" row * - * @access public * @return object */ - function next_row($type = 'object') + public function next_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -364,14 +346,12 @@ class CI_DB_result { /** * Returns the "previous" row * - * @access public * @return object */ - function previous_row($type = 'object') + public function previous_row($type = 'object') { $result = $this->result($type); - - if (count($result) == 0) + if (count($result) === 0) { return $result; } @@ -394,17 +374,16 @@ 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 /* End of file DB_result.php */ /* Location: ./system/database/DB_result.php */ |