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
Next revisionBoth sides next revision
activerecord:getactiverecordsclass [2015/12/05 01:55] mnewnhamv5:activerecord:getactiverecordsclass [2016/01/13 02:15] – ↷ Page moved from activerecord:getactiverecordsclass to v5:activerecord:getactiverecordsclass mnewnham
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 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.txt · Last modified: 2018/07/02 14:17 by peterdd