v5:activerecord:getactiverecords
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
activerecord:getactiverecords [2015/12/04 22:35] – created mnewnham | v5:activerecord:getactiverecords [2018/07/02 14:19] (current) – prefer functions start lowercase (#430) peterdd | ||
---|---|---|---|
Line 2: | Line 2: | ||
~~NOTOC~~ | ~~NOTOC~~ | ||
<WRAP right box> | <WRAP right box> | ||
- | == syntax | + | == Syntax |
- | mixed getActiveRecords( | + | |
- | string $tableName, | + | string $tableName, |
- | optional string | + | optional string |
- | optional mixed[] $bindarr=false, | + | optional mixed[] $bindarr=false, |
- | optional mixed[] $primaryKeyArray=false | + | optional mixed[] $primaryKeyArray=false |
- | ) | + | ) |
</ | </ | ||
- | /** | + | ------------------------------------- |
- | * GetActiveRecordsClass Performs an ' | + | |
- | * | + | |
- | * @param mixed $class This string represents the class of the current active record | + | |
- | * @param mixed $table Table used by the active record object | + | |
- | * @param mixed $whereOrderBy Where, order, by clauses | + | |
- | * @param mixed $bindarr | + | |
- | * @param mixed $primkeyArr | + | |
- | * @param array $extra Query extras: limit, offset... | + | |
- | * @param mixed $relations Associative array: table' | + | |
- | * @access public | + | |
- | * @return void | + | |
- | */ | + | |
- | function GetActiveRecordsClass( | + | |
- | $class, $table, | + | |
- | $extra=array(), | + | |
- | $relations=array()) | + | |
- | { | + | |
- | global $_ADODB_ACTIVE_DBS; | + | |
- | ## reduce overhead of adodb.inc.php | + | |
- | ## if adodb-active-recordx is loaded | + | |
- | if (!isset($_ADODB_ACTIVE_DBS))include_once(ADODB_DIR.'/ | + | |
- | return adodb_GetActiveRecordsClass($this, | + | |
- | } | + | |
- | + | ||
- | function GetActiveRecords($table, | + | |
- | { | + | |
- | $arr = $this-> | + | |
- | return $arr; | + | |
- | } | + | |
===== Description ===== | ===== Description ===== | ||
+ | This method retrieves an array of ADOdb_Active_Records. | ||
+ | ===== Parameters ===== | ||
+ | ==== $tableName ==== | ||
+ | Table used by the active record object | ||
+ | ==== $where ==== | ||
+ | Where clause | ||
+ | ==== $bindarr ==== | ||
+ | For more information on the use of '' | ||
+ | ==== $primaryKeyArray ==== | ||
+ | |||
==== Usage ==== | ==== Usage ==== | ||
<code php> | <code php> | ||
Line 51: | Line 32: | ||
$db-> | $db-> | ||
- | $activeRecs | + | $table = ' |
- | | + | $whereOrderBy = "name LIKE ' |
+ | $primaryKeys | ||
+ | $activeRecArr | ||
+ | foreach($activeRecArr as $rec) | ||
+ | { | ||
+ | $rec->id = rand(); | ||
+ | $rec-> | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | And to retrieve all records ordered by specific fields: | ||
+ | <code php> | ||
+ | |||
+ | $whereOrderBy = "1=1 ORDER BY Name"; | ||
+ | $activeRecArr = $db-> | ||
+ | /* | ||
+ | * To use bind variables (assuming ? is the place-holder for your database): | ||
+ | */ | ||
+ | |||
+ | $activeRecArr = $db-> | ||
+ | array(' | ||
+ | |||
+ | /* | ||
+ | Define the primary key field[s] of the table by passing an array of field names: | ||
+ | */ | ||
+ | $activeRecArr = $db-> | ||
+ | array(' | ||
</ | </ | ||
{{tag> | {{tag> |
v5/activerecord/getactiverecords.1449264917.txt.gz · Last modified: 2017/04/21 11:21 (external edit)