Class miSqlRecordset

Description

Handle and manage the reading of data from database.

This class only read data from a given database table with necessary ordering and filtering.

  • copyright: Copyright (c) 2003-2006 Mirchev Ideas Ltd. All rights reserved.

Located in /model/SqlRecordset.php (line 17)


	
			
Variable Summary
Method Summary
miSqlRecordset __construct (string|array $table)
void addFilter (miSqlFilter $filter)
void addFilters (array $filters)
void addJoinCondition (string $joinType, string $joinTable, string $joinCondition)
array getAllFields ()
array getAllRecords ()
string getGroupByClause ()
array getRecords ()
array getRecordsByIndex (int $fromIndex, int $numRecords)
string getSelectQuery ()
string getSqlFilterClause ()
string getSqlLimitClause (int $fromIndex, int $numRecords)
string getSqlOrderClause ()
string getTable ()
string getTablesClause ()
void setGroupBy (string $groupBy)
void setHavingFilterNames (array $filterNames)
void setOrder (string $sortBy, string $sortDir)
void setRecordsLimit (int $from, int $num)
void setSelectFields ( $selectFields, array $fields)
Variables
mixed $_allFields = null (line 63)
  • access: protected
mixed $_filters = array() (line 53)
  • access: protected
mixed $_firstRecordIndex = 0 (line 28)
  • access: protected
mixed $_groupBy = '' (line 48)
  • access: protected
mixed $_havingFilterNames = array() (line 58)
  • access: protected
mixed $_joinConditions = array() (line 78)
  • access: protected
mixed $_numRecords = false (line 33)
  • access: protected
mixed $_selectedFields = array() (line 73)
  • access: protected
mixed $_selectFields = array() (line 68)
  • access: protected
mixed $_sortBy = '' (line 38)
  • access: protected
mixed $_sortDir = '' (line 43)
  • access: protected
mixed $_table (line 23)
  • access: protected
Methods
Constructor __construct (line 97)

miSqlRecordset constructor

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  ?>
  4.  <?php
  5.  $recordset new miSqlRecordset(array('firstTable''secondTable'));
  6.  ?>

  • access: public
miSqlRecordset __construct (string|array $table)
  • string|array $table: database table name, or several table names
addFilter (line 162)

Adds a filter object

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->addFilter($filter);
  4.  ?>

  • access: public
void addFilter (miSqlFilter $filter)
  • array $filter: a filter object
addFilters (line 173)

Adds multiple filters

  • access: public
void addFilters (array $filters)
  • array $filters: array of filter objects
addJoinCondition (line 109)

Adds join condition

  • access: public
void addJoinCondition (string $joinType, string $joinTable, string $joinCondition)
  • string $joinType: the type of the join, eg. INNER, LEFT
  • string $joinTable: the table to be joined
  • string $joinCondition: the condition of the join
getAllFields (line 526)

Returns all fields of the recordset table(s) The result of the function is cached. Call only after all join conditions have been added.

  • return: the field names
  • access: public
array getAllFields ()
getAllRecords (line 502)

Read all records from the database table The result is limited to the given filter clause and is returned in order specify by order clause

  • return: rows returned from database
  • throws: miDBException
  • access: public
array getAllRecords ()
getGroupByClause (line 371)

Returns the group by clause

  • return: sql clause
  • access: protected
string getGroupByClause ()
getJoinConditionsClause (line 343)

Return the join conditions sql

  • return: the join conditions sql
  • access: protected
string getJoinConditionsClause ()
getRecords (line 455)

Read rows from a database table.

The result reply to the given filter clause and is returned in order specify by order clause

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->setOrder($tableField'ASC');
  4.  $recordset->addFilter($filter);
  5.  $rows $recordset->getRecords();
  6.  ?>

  • return: rows returned from database
  • throws: miDBException
  • access: public
array getRecords ()
getRecordsByIndex (line 482)

Read fixed number of rows from a given index in a database table.

The result reply to the given filter clause and is returned in order specify by order clause If both $fromIndex and $numRecords are false returns all records

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->setOrder($tableField'ASC');
  4.  $rows $recordset->getRecordsByIndex($fromIndex$numRecords);
  5.  ?>

  • return: rows returned from database
  • throws: miDBException
  • access: public
array getRecordsByIndex (int $fromIndex, int $numRecords)
  • int $fromIndex: from which record index to start
  • int $numRecords: number of rows to be read
getRecordsCount (line 418)

Return the number of all rows in a database table that reply to the given filter clause

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->addFilter($arrayFilter);
  4.  $count $recordset->getRecordsCount();
  5.  ?>

  • return: number of all rows in a database table
  • throws: miDBException
  • access: public
int getRecordsCount ()
getSelectedFields (line 514)

Returns the list of all selected fields An empty array is returned of no query has been executed

  • return: the selected field names
  • access: public
array getSelectedFields ()
getSelectQuery (line 383)

Returns the query to select all records for the recordset (without a LIMIT clause)

  • return: sql clause
  • access: public
string getSelectQuery ()
getSqlFilterClause (line 260)

Return all the specified filter clauses as a string

  • return: all the specified filter clauses as a string
  • throws: miConfigurationException
  • access: protected
string getSqlFilterClause ()
getSqlFilterHavingClause (line 301)

Return all the specified HAVING filter clauses as a string

  • return: all the specified HAVING filter clauses as a string
  • throws: miConfigurationException
  • access: protected
string getSqlFilterHavingClause ()
getSqlLimitClause (line 330)

Return the limit as a sql code

  • return: the limit as a sql code
  • access: protected
string getSqlLimitClause (int $fromIndex, int $numRecords)
  • int $fromIndex: from which record index to start
  • int $numRecords: number of rows to be read
getSqlOrderClause (line 238)

Return the order clause

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->setOrder($tableField'ASC');
  4.  $order $recordset->getSqlOrderClause();
  5.  ?>

  • return: order clause
  • access: protected
string getSqlOrderClause ()
getTable (line 547)

Returns the table name for the current recordset

  • access: public
string getTable ()
getTablesClause (line 358)

Returns the table sql clause

  • return: the table clause
  • access: protected
string getTablesClause ()
setGroupBy (line 143)

Sets group by fields The param is directly added after the GROUP BY clause

  • access: public
void setGroupBy (string $groupBy)
  • string $groupBy: the group by fields
setHavingFilterNames (line 184)

Sets the names of the filters to be used in a HAVING clause instead of WHERE

  • access: public
void setHavingFilterNames (array $filterNames)
  • array $filterNames: array of filter names to be used in a HAVING clause instead of WHERE
setOrder (line 130)

Sets the field by which the result of the query will be ordered and the direction of ordering - ascending or descending.

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->setOrder($tableField'ASC');
  4.  ?>

  • access: public
void setOrder (string $sortBy, string $sortDir)
  • string $sortBy: database table field name
  • string $sortDir: direction of ordering - ascending or descending
setRecordsLimit (line 216)

Sets how many rows to be read from the databse

Example:

  1.  <?php
  2.  $recordset new miSqlRecordset('tableName');
  3.  $recordset->setRecordsLimit(520);
  4.  ?>

  • access: public
void setRecordsLimit (int $from, int $num)
  • int $from: from which record index to start
  • int $num: how many rows to read
setSelectFields (line 196)

Sets the select fields Defaults to * (all columns)

  • access: public
void setSelectFields ( $selectFields, array $fields)
  • array $fields
  • $selectFields

Documentation generated on Thu, 08 May 2008 16:57:38 +0300 by phpDocumentor 1.4.1