ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:getactiverecordsclass

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
activerecord:getactiverecordsclass [2015/12/05 01:55] mnewnhamv5:activerecord:getactiverecordsclass [2018/07/02 14:17] (current) – prefer functions start lowercase (#430) peterdd
Line 16: Line 16:
  
 ===== Description ===== ===== Description =====
- +This allows you to retrieve an array of objects derived from ADOdb_Active_Records. Returns false if an error occurs.
-GetActiveRecordsClass Performs an 'ALL' query +
  
 ===== Parameters =====  ===== Parameters ===== 
Line 27: Line 26:
  Where, order, by clause  Where, order, by 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 35:
 ==== Usage ==== ==== Usage ====
 <code php> <code php>
-include 'adodb/adodb.inc.php'; +class Product extends ADOdb_Active_Record{}; 
-include 'adodb/adodb-activerecord.inc.php';+$table = 'products'; 
 +$whereOrderBy = "name LIKE 'A%' ORDER BY Name"; 
 +$activeRecArr = $db->getActiveRecordsClass('Product', 
 +                                            $table, 
 +                                            $whereOrderBy);
  
-$db = NewADOConnection('mysqli'); +/* 
-$db->connect('','user','password','employees');+* the objects in $activeRecArr are of class 'Product' 
 +*/ 
 +foreach($activeRecArr as $rec) { 
 + $rec->id = rand(); 
 + $rec->save(); 
 +
 +</code> 
 + 
 +To use bind variables (assuming ? is the place-holder for your database): 
 +<code php> 
 + 
 +$activeRecArr = $db->getActiveRecordsClass($className,$tableName, 'name LIKE ?', 
 + array('A%')); 
 +/* 
 +* You can also define the primary keys of the table by passing an array of field names: 
 +*/ 
 + 
 +$activeRecArr = $db->getActiveRecordsClass($className,$tableName, 'name LIKE ?', 
 + array('A%'), array('id'));
  
-$activeRecs = $db->GetActiveRecords('departments'); 
-            
 </code> </code>
 +
 {{tag>[Active_Record]}}        {{tag>[Active_Record]}}       
v5/activerecord/getactiverecordsclass.1449276953.txt.gz · Last modified: 2017/04/21 11:21 (external edit)