v5:activerecord:getactiverecordsclass
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
activerecord:getactiverecordsclass [2015/12/04 22:35] – created mnewnham | v5:activerecord:getactiverecordsclass [2018/07/02 14:17] (current) – prefer functions start lowercase (#430) peterdd | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
~~NOTOC~~ | ~~NOTOC~~ | ||
<WRAP right box> | <WRAP right box> | ||
- | == syntax | + | == Syntax |
- | mixed getActiveRecords( | + | void getActiveRecordsClass( |
- | string $tableName, | + | string $class, |
- | optional string | + | string $tableName, |
- | optional mixed[] $bindarr=false, | + | |
- | optional mixed[] $primaryKeyArray=false | + | |
- | ) | + | |
+ | optional mixed[] $queryExtras=array(), | ||
+ | | ||
+ | | ||
</ | </ | ||
- | /** | + | |
- | * 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 -- moved to adodb-active-record.inc.php | + | |
- | ## if adodb-active-recordx is loaded -- should be no issue as they will probably use Find() | + | |
- | if (!isset($_ADODB_ACTIVE_DBS))include_once(ADODB_DIR.'/ | + | |
- | return adodb_GetActiveRecordsClass($this, | + | |
- | } | + | |
- | + | ||
- | function GetActiveRecords($table, | + | |
- | { | + | |
- | $arr = $this-> | + | |
- | return $arr; | + | |
- | } | + | |
===== Description ===== | ===== Description ===== | ||
+ | This allows you to retrieve an array of objects derived from ADOdb_Active_Records. Returns false if an error occurs. | ||
+ | |||
+ | ===== Parameters ===== | ||
+ | ====$class ==== | ||
+ | This string represents the class of the current active record | ||
+ | ==== $table ==== | ||
+ | Table used by the active record object | ||
+ | ==== $whereOrderBy==== | ||
+ | | ||
+ | ==== $bindarr ==== | ||
+ | For more information on the use of '' | ||
+ | ==== $primaryKeyArray ==== | ||
+ | |||
+ | ==== $queryExtras ==== | ||
+ | Query extras: limit, offset... | ||
+ | ==== $relationsData ==== | ||
==== Usage ==== | ==== Usage ==== | ||
<code php> | <code php> | ||
- | include | + | class Product extends ADOdb_Active_Record{}; |
- | include | + | $table = 'products'; |
+ | $whereOrderBy = "name LIKE 'A%' ORDER BY Name"; | ||
+ | $activeRecArr = $db-> | ||
+ | $table, | ||
+ | $whereOrderBy); | ||
- | $db = NewADOConnection('mysqli'); | + | /* |
- | $db->connect('',' | + | * the objects in $activeRecArr are of class 'Product' |
+ | */ | ||
+ | foreach($activeRecArr as $rec) { | ||
+ | $rec-> | ||
+ | $rec-> | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | To use bind variables (assuming ? is the place-holder for your database): | ||
+ | <code php> | ||
+ | |||
+ | $activeRecArr = $db->getActiveRecordsClass($className, | ||
+ | array('A%')); | ||
+ | /* | ||
+ | * You can also define the primary keys of the table by passing an array of field names: | ||
+ | */ | ||
+ | |||
+ | $activeRecArr = $db-> | ||
+ | array('A%'), array(' | ||
- | $activeRecs = $db-> | ||
- | |||
</ | </ | ||
+ | |||
{{tag> | {{tag> |
v5/activerecord/getactiverecordsclass.1449264934.txt.gz · Last modified: 2017/04/21 11:21 (external edit)