SourceForge.net LogoPHPGallue
[ class tree: libbase ] [ index: libbase ] [ all elements ]

Class: GALResult

Source Location: /libbase/result.inc.php

Class Overview


Result of a database query.


Implements interfaces:

Variables

Methods


Child classes:

GALTableIterator
This class provides access to a set of GALTableRow objects.

Class Details

[line 438]
Result of a database query.

This class encapsulates a MySQL query result and provides access to the rows as GALRow objects.




[ Top ]


Class Variables

$fields =

[line 473]

Associative array that maps the field name to the field's index.

This array maps the name of a field to the position of a field. In SELECT `name`, `id`, `adress` FROM `users` the value of

  1. $fields['id'];
would be 1. This array is needed, because function like mysql_field_flags() take a field offset and not a field name to specify a field.




Tags:

var:  Associative array where the field names are keys and the values are integers.
access:  protected

Type:   array


[ Top ]

$handle =

[line 444]

The MySQL result ressource.



Tags:

access:  protected

Type:   resource


[ Top ]

$index =  0

[line 450]

Index of the current row.



Tags:

access:  protected

Type:   int


[ Top ]

$num_fields =

[line 462]

Number of fields in this database result.



Tags:

var:  A positive integer.
access:  protected

Type:   int


[ Top ]

$num_rows =

[line 456]

Number of rows in this database result.



Tags:

var:  A positive integer.
access:  protected

Type:   int


[ Top ]

$rowFactory =

[line 475]



Tags:

access:  protected

Type:   mixed


[ Top ]



Class Methods


constructor __construct [line 485]

GALResult __construct( resource $handle)

Initializes a GALResult.

A GALResult can be constructed "by hand" simply by calling this constructor with a valid MySQL query resource, or by using the GALDatabase::query() method which returns a GALResult.




Overridden in child classes as:

GALTableIterator::__construct()
Initializes this object.
GALUserIterator::__construct()
GALNodeIterator::__construct()
Initialize the $glb variable, then call parent constructor.
GALFilmIterator::__construct()
Initialize the $glb variable, then call parent constructor.
GALHelpIterator::__construct()
GALCommentIterator::__construct()
GALImageIterator::__construct()
Initialize the $glb variable, then call parent constructor.
GALSeriesIterator::__construct()
GALGroupIterator::__construct()
Initializes the $glb variable, then calls the parent constructor.
GALInstanceIterator::__construct()
Initialize the $glb variable, then call parent constructor.
GALLoginIterator::__construct()
GALJobIterator::__construct()
Initialize the $glb variable, then call parent constructor.
GALCategoryIterator::__construct()
Initialize the $glb variable, then call parent constructor.
GALTokenIterator::__construct()

Parameters:

resource   $handle   E.g. the result of mysql_query().

[ Top ]

destructor __destruct [line 505]

void __destruct( )

Free memory associated with this query result.



Overridden in child classes as:

GALTableIterator::__destruct()
Overwrite inherited destructor.

[ Top ]

method buildRow [line 813]

GALRow buildRow( GALResult $source, array &$data)

Implements the GALRowFactory interface.



Overridden in child classes as:

GALTableIterator::buildRow()
Implements the GALRowFactory interface.
GALUserIterator::buildRow()
GALNodeIterator::buildRow()
GALFilmIterator::buildRow()
GALHelpIterator::buildRow()
GALCommentIterator::buildRow()
Constructs the items of this iterator.
GALImageIterator::buildRow()
GALSeriesIterator::buildRow()
GALGroupIterator::buildRow()
Constructs the items of this iterator.
GALInstanceIterator::buildRow()
GALLoginIterator::buildRow()
GALJobIterator::buildRow()
GALCategoryIterator::buildRow()
Constructs the items of this iterator.
GALTokenIterator::buildRow()


Implementation of:
GALRowFactory::buildRow()
Builds a row.

Parameters:

GALResult   $source  
array   &$data   Reference to an array containing the row data

[ Top ]

method count [line 729]

int count( )

Returns the number of rows in this result.



Tags:




Implementation of:
GALResultIterator::count()
Returns the number of rows in this list or set.
[ Top ]

method countFields [line 595]

int countFields( )

Returns the number of fields contained in a result.



Tags:



Overridden in child classes as:

GALTableIterator::countFields()
Returns the number of fields contained in a result.


Implementation of:
GALDesc::countFields()
Returns the number of fields contained in a result.
[ Top ]

method data_seek [line 633]

void data_seek( int $index)

Sets the internal pointer to the specified row.

This method sets the internal row pointer so that the next row returned by fetch() is the one on position $index in the result (starting from zero).




Tags:

throws:  GAL_EDatabase If the index is out of range.
see:  GALResultIterator::data_seek()


Overridden in child classes as:

GALTableIterator::data_seek()
Sets the internal pointer to the specified row.


Implementation of:
GALResultIterator::data_seek()
Moves the internal pointer to the row with the given position inside the list.

Parameters:

int   $index  

[ Top ]

method fetch [line 674]

GALRow fetch( )

Fetches a row from the MySQL query result.

This function fetches the current row (indicated by $index) from the database result, increases the internal pointer by one, constructs a GALRow object and returns it.

(Information for people writing classes that inherit from this class) Note that mysql_data_seek() is not called inside this function, so changing the $index variable is not sufficient to specify the next row that will be fetched. Please use data_seek()!




Tags:

return:  The row that has been fetched, or FALSE if this iterator has reached the end.
see:  GALResultIterator::fetch()


Overridden in child classes as:

GALTableIterator::fetch()
Fetches the current row from the database.


Implementation of:
GALResultIterator::fetch()
Fetches the row the internal pointer points to and sets the internal pointer to the next row.
[ Top ]

method filter [line 740]

GALRowSet filter( string $callback)

Filters the rows of this result with a callback function.



Tags:

return:  All rows where the callback function returned TRUE.
see:  GALResultIterator::filter()



Implementation of:
GALResultIterator::filter()
Filters the rows of this iterator with a callback function.

Parameters:

string   $callback   The name of a callback function.

[ Top ]

method getFields [line 585]

array getFields( )

Returns all fields contained in a result.



Tags:

return:  An array with all field names as strings.
see:  GALDesc::getFields()


Overridden in child classes as:

GALTableIterator::getFields()
Returns all fields contained in this result.


Implementation of:
GALDesc::getFields()
Returns all fields contained in a result.
[ Top ]

method getFlags [line 517]

string getFlags( string $field)

Gets the flags of the given field.



Tags:

throws:  GAL_EDatabase If the field name is invalid.
see:  GALDesc::getFlags()


Overridden in child classes as:

GALTableIterator::getFlags()
Gets the flags of the given field.


Implementation of:
GALDesc::getFlags()
Gets the flags of the given field.

Parameters:

string   $field   The name of a field.

[ Top ]

method getLength [line 553]

int getLength( string $field)

Gets the length of the given field.

Wrapper for mysql_field_len().




Tags:

throws:  GAL_EDatabase If the field name is invalid.
see:  GALDesc::getLength()


Overridden in child classes as:

GALTableIterator::getLength()
Gets the length of the given field.


Implementation of:
GALDesc::getLength()
Gets the length of the given field.

Parameters:

string   $field   The name of a field.

[ Top ]

method getParent [line 619]

GALResult getParent( )

Returns a reference to this object.

A GALResult hasn't got a parent, so it is a top level entity and getParent() returns a reference to this object itself ($this). This behavior is overridden in GALTableIterator::getParent().




Tags:

return:  The $this reference which is an instance of GALResult.
see:  GALDesc::getParent()


Overridden in child classes as:

GALTableIterator::getParent()
Returns the parent of this result.


Implementation of:
GALDesc::getParent()
Return the top level parent of an entity.
[ Top ]

method getRowFactory [line 829]

GALRowFactory getRowFactory( )

Returns the factory to construct rows.



Overridden in child classes as:

GALTableIterator::getRowFactory()
Returns the factory to construct rows.

[ Top ]

method getTable [line 571]

string getTable( string $field)

Gets the name of the table the given field is contained in.

Wrapper for mysql_field_table().




Tags:

throws:  GAL_EDatabase If the field name is invalid.
see:  GALDesc::getTable()


Overridden in child classes as:

GALTableIterator::getTable()
Gets the name of the table the given field is contained in.


Implementation of:
GALDesc::getTable()
Gets the name of the table the given field is contained in.

Parameters:

string   $field   The name of a field.

[ Top ]

method getType [line 535]

string getType( string $field)

Gets the type of the given field.

Wrapper for mysql_field_type().




Tags:

throws:  GAL_EDatabase If the field name is invalid.
see:  GALDesc::getType()


Overridden in child classes as:

GALTableIterator::getType()
Gets the type of the given field.


Implementation of:
GALDesc::getType()
Gets the type of the given field.

Parameters:

string   $field   The name of a field.

[ Top ]

method isField [line 606]

bool isField( string $field)

Checks if the given field is contained in a result.



Tags:




Implementation of:
GALDesc::isField()
Checks if the given field is contained in a result.

Parameters:

string   $field   The name of a field.

[ Top ]

method iterator [line 802]

GALIteratorIterator iterator( )

Creates a new iterator on the data of this result.



Tags:




Implementation of:
GALResultIterator::iterator()
Returns a new ResultIterator on the data of this iterator.
[ Top ]

method position [line 656]

int position( )

Returns the index of the current row.

This method returns the index of the row that will be returned by the next call of fetch() (starting from zero)




Tags:

return:  An integer >= 0.
see:  GALResultIterator::position()



Implementation of:
GALResultIterator::position()
Gets the index of the row the internal pointer points top.
[ Top ]

method rewind [line 693]

bool rewind( )

Sets the internal pointer to zero.

This method changes the internal pointer so that it points to the first row, i.e. row 0.




Tags:

return:  FALSE if there are no rows in the result, TRUE otherwise.
see:  GALResultIterator::rewind()



Implementation of:
GALResultIterator::rewind()
Moves the internal pointer to position 0.
[ Top ]

method row [line 715]

void row( mixed $index)

Fetches the row with the specified index (starting from 0).

This method fetches the row that has the specified index inside this result without changing the internal pointer. It returns the same as

  1.  $this->data_seek($index);
  2.  $this->fetch();
, but the internal pointer keeps unchanged.




Tags:

throws:  GAL_EDatabase If the row index is out of range.
see:  GALResultIterator::row()



Implementation of:
GALResultIterator::row()
Fetches the row with the given index.
[ Top ]

method setRowFactory [line 821]

void setRowFactory( GALRowFactory $factory)

Sets the factory to construct rows.



Overridden in child classes as:

GALTableIterator::setRowFactory()
Changing the row factory is not possible.

Parameters:

GALRowFactory   $factory  

[ Top ]

method verticalFetch [line 779]

array verticalFetch( string $field)

Returns the value of the specified field in all rows of this iterator.

In the following example the table "users" contains these three rows:

  • name, id
  • 'Kurt', 1
  • 'Egon', 2
  • 'Herbert', 3
    1.  $database new GALDatabase($host$user$password$database);
    2.  $result $database->query("SELECT `name`, `id` FROM `users`");
    3.  $names $result->verticalFetch('name');
    4.  print_r($names);
    would print
     Array
     (
         [0] => Kurt
         [1] => Egon
         [2] => Herbert
     )
to stdout.




Tags:

return:  An array with all values of the specified field in this result.
throws:  GAL_EDatabase If the specified field doesn't exist.


Overridden in child classes as:

GALTableIterator::verticalFetch()
Returns the value of the specified field in all rows of this iterator.


Implementation of:
GALResultIterator::verticalFetch()
Returns the value of a field in all rows of this iterator.

Parameters:

string   $field   The name of a field.

[ Top ]


Documentation generated on Wed, 16 Aug 2006 15:36:27 +0200 by phpDocumentor 1.3.0RC6