ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:getactiverecords

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
activerecord:getactiverecords [2015/12/05 01:19] – [Usage] mnewnhamv5:activerecord:getactiverecords [2016/01/19 05:02] – ↷ Links adapted because of a move operation 66.249.75.209
Line 2: Line 2:
 ~~NOTOC~~ ~~NOTOC~~
 <WRAP right box> <WRAP right box>
-== syntax == +== Syntax == 
-  void getActiveRecords(+  bool getActiveRecords(
     string $tableName,     string $tableName,
     optional string  $where=false,     optional string  $where=false,
Line 11: Line 11:
  
 </WRAP> </WRAP>
 +-------------------------------------
 ===== Description ===== ===== Description =====
- +This method retrieves an array of ADOdb_Active_Records.
-GetActiveRecordsClass Performs an 'ALL' query  +
 ===== Parameters =====  ===== Parameters ===== 
  
Line 23: Line 21:
  Where clause  Where clause
 ==== $bindarr ==== ==== $bindarr ====
-For more information on the use of ''Bind'' variables, see [[reference:execute()]].+For more information on the use of ''Bind'' variables, see [[v5:reference:connection:execute]].
 ==== $primaryKeyArray ==== ==== $primaryKeyArray ====
    
Line 36: Line 34:
 $table        = 'departments'; $table        = 'departments';
 $whereOrderBy = "name LIKE 'A%' ORDER BY Name"; $whereOrderBy = "name LIKE 'A%' ORDER BY Name";
-$activeRecArr = $db->GetActiveRecords($table, $whereOrderBy);+$primaryKeys  = array('id'); 
 +$activeRecArr = $db->getActiveRecords($table, $whereOrderBy,$primaryKeys);
 foreach($activeRecArr as $rec)  foreach($activeRecArr as $rec) 
 { {
Line 42: Line 41:
     $rec->save();     $rec->save();
 }            }           
 +</code>
 +
 +And to retrieve all records ordered by specific fields:
 +<code php>
 +
 +$whereOrderBy = "1=1 ORDER BY Name";
 +$activeRecArr = $db->GetActiveRecords($table);
 +/*
 +* To use bind variables (assuming ? is the place-holder for your database):
 +*/
 +
 +$activeRecArr = $db->getActiveRecords($tableName, 'name LIKE ?',
 + array('A%'));
 +
 +/*
 +Define the primary key field[s] of the table by passing an array of field names:
 +*/
 +$activeRecArr = $db->GetActiveRecords($tableName, 'name LIKE ?',
 + array('A%'), array('id'));
 </code> </code>
 {{tag>[Active_Record]}}        {{tag>[Active_Record]}}       
v5/activerecord/getactiverecords.txt · Last modified: 2018/07/02 14:19 by peterdd