summaryrefslogtreecommitdiffstats
path: root/system/database/DB_result.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/DB_result.php')
-rw-r--r--system/database/DB_result.php142
1 files changed, 69 insertions, 73 deletions
diff --git a/system/database/DB_result.php b/system/database/DB_result.php
index 48d66c8e4..690734b08 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
+ * An open source application development framework for PHP 5.2.4 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,36 @@
* 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;
+ public function __construct(&$driver_object)
+ {
+ $this->conn_id = $driver_object->conn_id;
+ $this->result_id = $driver_object->result_id;
+ }
/**
* 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
+ * @return 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,8 +71,8 @@ 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
*/
public function custom_result_object($class_name)
{
@@ -79,7 +93,6 @@ class CI_DB_result {
while ($row = $this->_fetch_object())
{
$object = new $class_name();
-
foreach ($row as $key => $value)
{
$object->$key = $value;
@@ -95,10 +108,9 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
- * Query result. "object" version.
+ * Query result. "object" version.
*
- * @access public
- * @return object
+ * @return array
*/
public function result_object()
{
@@ -129,7 +141,6 @@ class CI_DB_result {
/**
* Query result. "array" version.
*
- * @access public
* @return array
*/
public function result_array()
@@ -161,7 +172,6 @@ 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
@@ -185,8 +195,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,8 +205,7 @@ class CI_DB_result {
/**
* Assigns an item into a particular column slot
*
- * @access public
- * @return object
+ * @return void
*/
public function set_row($key, $value = NULL)
{
@@ -212,11 +221,10 @@ class CI_DB_result {
{
$this->row_data[$k] = $v;
}
-
return;
}
- if ($key != '' AND ! is_null($value))
+ if ($key != '' && ! is_null($value))
{
$this->row_data[$key] = $value;
}
@@ -227,19 +235,17 @@ class CI_DB_result {
/**
* Returns a single result row - custom object version
*
- * @access public
* @return object
*/
public function custom_row_object($n, $type)
{
$result = $this->custom_result_object($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
- if ($n != $this->current_row AND isset($result[$n]))
+ if ($n != $this->current_row && isset($result[$n]))
{
$this->current_row = $n;
}
@@ -250,19 +256,17 @@ class CI_DB_result {
/**
* Returns a single result row - object version
*
- * @access public
* @return object
*/
public function row_object($n = 0)
{
$result = $this->result_object();
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
- if ($n != $this->current_row AND isset($result[$n]))
+ if ($n != $this->current_row && isset($result[$n]))
{
$this->current_row = $n;
}
@@ -275,19 +279,17 @@ class CI_DB_result {
/**
* Returns a single result row - array version
*
- * @access public
* @return array
*/
public function row_array($n = 0)
{
$result = $this->result_array();
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
- if ($n != $this->current_row AND isset($result[$n]))
+ if ($n != $this->current_row && isset($result[$n]))
{
$this->current_row = $n;
}
@@ -295,24 +297,17 @@ class CI_DB_result {
return $result[$this->current_row];
}
-
// --------------------------------------------------------------------
/**
* Returns the "first" row
*
- * @access public
* @return 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 +315,12 @@ class CI_DB_result {
/**
* Returns the "last" row
*
- * @access public
* @return 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 +328,12 @@ class CI_DB_result {
/**
* Returns the "next" row
*
- * @access public
* @return object
*/
public function next_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -364,14 +351,12 @@ class CI_DB_result {
/**
* Returns the "previous" row
*
- * @access public
* @return object
*/
public function previous_row($type = 'object')
{
$result = $this->result($type);
-
- if (count($result) == 0)
+ if (count($result) === 0)
{
return $result;
}
@@ -386,11 +371,23 @@ class CI_DB_result {
// --------------------------------------------------------------------
/**
+ * Returns an unbuffered row and move pointer to next row
+ *
+ * @return mixed either a result object or array
+ */
+ public function unbuffered_row($type = 'object')
+ {
+ return ($type !== 'array') ? $this->_fetch_object() : $this->_fetch_assoc();
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* The following functions are normally overloaded by the identically named
* methods in the platform-specific driver -- except when query caching
- * is used. When caching is enabled we do not load the other driver.
+ * is used. When caching is enabled we do not load the other driver.
* These functions are primarily here to prevent undefined function errors
- * when a cached result object is in use. They are not otherwise fully
+ * when a cached result object is in use. They are not otherwise fully
* operational due to the unavailability of the database resource IDs with
* cached results.
*/
@@ -398,13 +395,12 @@ class CI_DB_result {
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; }
+ public function free_result() { $this->result_id = FALSE; }
+ protected function _data_seek() { return FALSE; }
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 */
+/* Location: ./system/database/DB_result.php */ \ No newline at end of file