2012-11-09 12:18:50 +00:00
|
|
|
<?php defined('SYSPATH') OR die('No direct script access.');
|
2010-08-21 04:43:03 +00:00
|
|
|
/**
|
2011-05-13 06:00:25 +00:00
|
|
|
* MySQL database result. See [Results](/database/results) for usage and examples.
|
2010-08-21 04:43:03 +00:00
|
|
|
*
|
|
|
|
* @package Kohana/Database
|
|
|
|
* @category Query/Result
|
|
|
|
* @author Kohana Team
|
|
|
|
* @copyright (c) 2008-2009 Kohana Team
|
|
|
|
* @license http://kohanaphp.com/license
|
|
|
|
*/
|
|
|
|
class Kohana_Database_MySQL_Result extends Database_Result {
|
|
|
|
|
|
|
|
protected $_internal_row = 0;
|
|
|
|
|
2011-05-13 06:00:25 +00:00
|
|
|
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
|
2010-08-21 04:43:03 +00:00
|
|
|
{
|
2011-05-13 06:00:25 +00:00
|
|
|
parent::__construct($result, $sql, $as_object, $params);
|
2010-08-21 04:43:03 +00:00
|
|
|
|
|
|
|
// Find the number of rows in the result
|
|
|
|
$this->_total_rows = mysql_num_rows($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
if (is_resource($this->_result))
|
|
|
|
{
|
|
|
|
mysql_free_result($this->_result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function seek($offset)
|
|
|
|
{
|
|
|
|
if ($this->offsetExists($offset) AND mysql_data_seek($this->_result, $offset))
|
|
|
|
{
|
|
|
|
// Set the current row to the offset
|
|
|
|
$this->_current_row = $this->_internal_row = $offset;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function current()
|
|
|
|
{
|
|
|
|
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
|
2011-05-13 06:00:25 +00:00
|
|
|
return NULL;
|
2010-08-21 04:43:03 +00:00
|
|
|
|
|
|
|
// Increment internal row for optimization assuming rows are fetched in order
|
|
|
|
$this->_internal_row++;
|
|
|
|
|
|
|
|
if ($this->_as_object === TRUE)
|
|
|
|
{
|
|
|
|
// Return an stdClass
|
|
|
|
return mysql_fetch_object($this->_result);
|
|
|
|
}
|
|
|
|
elseif (is_string($this->_as_object))
|
|
|
|
{
|
|
|
|
// Return an object of given class name
|
2011-05-13 06:00:25 +00:00
|
|
|
return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params);
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Return an array of the row
|
|
|
|
return mysql_fetch_assoc($this->_result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End Database_MySQL_Result_Select
|