Database_MySQL_Result
Kohana_Database_MySQL_Result
Database_Result
Kohana_Database_Result

Class Contents

Class declared in MODPATH/database/classes/database/mysql/result.php on line 3.

Methods

public __construct( )
Kohana_Database_MySQL_Result

Source Code
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
{
	parent::__construct($result, $sql, $as_object, $params);

	// Find the number of rows in the result
	$this->_total_rows = mysql_num_rows($result);
}

public __destruct( )
Kohana_Database_MySQL_Result

Source Code
public function __destruct()
{
	if (is_resource($this->_result))
	{
		mysql_free_result($this->_result);
	}
}

public current( )
Kohana_Database_MySQL_Result

Source Code
public function current()
{
	if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
		return FALSE;

	// 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
		return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params);
	}
	else
	{
		// Return an array of the row
		return mysql_fetch_assoc($this->_result);
	}
}

public seek( )
Kohana_Database_MySQL_Result

Source Code
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 seek( )
Kohana_Database_MySQL_Result

Source Code
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 current( )
Kohana_Database_MySQL_Result

Source Code
public function current()
{
	if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
		return FALSE;

	// 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
		return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params);
	}
	else
	{
		// Return an array of the row
		return mysql_fetch_assoc($this->_result);
	}
}

public key( )
Kohana_Database_Result

Source Code
public function key()
{
	return $this->_current_row;
}

public key( )
Kohana_Database_Result

Source Code
public function key()
{
	return $this->_current_row;
}

public next( )
Kohana_Database_Result

Source Code
public function next()
{
	++$this->_current_row;
	return $this;
}

public offsetExists( )
Kohana_Database_Result

Source Code
public function offsetExists($offset)
{
	return ($offset >= 0 AND $offset < $this->_total_rows);
}

public as_array( )
Kohana_Database_Result

Source Code
public function as_array($key = NULL, $value = NULL)
{
	$results = array();

	if ($key === NULL AND $value === NULL)
	{
		// Indexed rows

		foreach ($this as $row)
		{
			$results[] = $row;
		}
	}
	elseif ($key === NULL)
	{
		// Indexed columns

		if ($this->_as_object)
		{
			foreach ($this as $row)
			{
				$results[] = $row->$value;
			}
		}
		else
		{
			foreach ($this as $row)
			{
				$results[] = $row[$value];
			}
		}
	}
	elseif ($value === NULL)
	{
		// Associative rows

		if ($this->_as_object)
		{
			foreach ($this as $row)
			{
				$results[$row->$key] = $row;
			}
		}
		else
		{
			foreach ($this as $row)
			{
				$results[$row[$key]] = $row;
			}
		}
	}
	else
	{
		// Associative columns

		if ($this->_as_object)
		{
			foreach ($this as $row)
			{
				$results[$row->$key] = $row->$value;
			}
		}
		else
		{
			foreach ($this as $row)
			{
				$results[$row[$key]] = $row[$value];
			}
		}
	}

	$this->rewind();

	return $results;
}

public cached( )
Kohana_Database_Result

Source Code
public function cached()
{
	return new Database_Result_Cached($this->as_array(), $this->_query, $this->_as_object);
}

public count( )
Kohana_Database_Result

Source Code
public function count()
{
	return $this->_total_rows;
}

public get( )
Kohana_Database_Result

Source Code
public function get($name, $default = NULL)
{
	$row = $this->current();

	if ($this->_as_object)
	{
		if (isset($row->$name))
			return $row->$name;
	}
	else
	{
		if (isset($row[$name]))
			return $row[$name];
	}

	return $default;
}

public valid( )
Kohana_Database_Result

Source Code
public function valid()
{
	return $this->offsetExists($this->_current_row);
}

public offsetGet( )
Kohana_Database_Result

Source Code
public function offsetGet($offset)
{
	if ( ! $this->seek($offset))
		return NULL;

	return $this->current();
}

final public offsetSet( )
Kohana_Database_Result

Source Code
final public function offsetSet($offset, $value)
{
	throw new Kohana_Exception('Database results are read-only');
}

final public offsetUnset( )
Kohana_Database_Result

Source Code
final public function offsetUnset($offset)
{
	throw new Kohana_Exception('Database results are read-only');
}

public next( )
Kohana_Database_Result

Source Code
public function next()
{
	++$this->_current_row;
	return $this;
}

public offsetExists( )
Kohana_Database_Result

Source Code
public function offsetExists($offset)
{
	return ($offset >= 0 AND $offset < $this->_total_rows);
}

public offsetGet( )
Kohana_Database_Result

Source Code
public function offsetGet($offset)
{
	if ( ! $this->seek($offset))
		return NULL;

	return $this->current();
}

final public offsetSet( )
Kohana_Database_Result

Source Code
final public function offsetSet($offset, $value)
{
	throw new Kohana_Exception('Database results are read-only');
}

final public offsetUnset( )
Kohana_Database_Result

Source Code
final public function offsetUnset($offset)
{
	throw new Kohana_Exception('Database results are read-only');
}

public prev( )
Kohana_Database_Result

Source Code
public function prev()
{
	--$this->_current_row;
	return $this;
}

public count( )
Kohana_Database_Result

Source Code
public function count()
{
	return $this->_total_rows;
}

public rewind( )
Kohana_Database_Result

Source Code
public function rewind()
{
	$this->_current_row = 0;
	return $this;
}

public rewind( )
Kohana_Database_Result

Source Code
public function rewind()
{
	$this->_current_row = 0;
	return $this;
}

public valid( )
Kohana_Database_Result

Source Code
public function valid()
{
	return $this->offsetExists($this->_current_row);
}