====== getActiveRecords ====== ~~NOTOC~~ == Syntax == bool getActiveRecords( string $tableName, optional string $where=false, optional mixed[] $bindarr=false, optional mixed[] $primaryKeyArray=false ) ------------------------------------- ===== 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 ''Bind'' variables, see [[v5:reference:connection:execute]]. ==== $primaryKeyArray ==== ==== Usage ==== include 'adodb/adodb.inc.php'; include 'adodb/adodb-activerecord.inc.php'; $db = NewADOConnection('mysqli'); $db->connect('','user','password','employees'); $table = 'departments'; $whereOrderBy = "name LIKE 'A%' ORDER BY Name"; $primaryKeys = array('id'); $activeRecArr = $db->getActiveRecords($table, $whereOrderBy,$primaryKeys); foreach($activeRecArr as $rec) { $rec->id = rand(); $rec->save(); } And to retrieve all records ordered by specific fields: $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')); {{tag>[Active_Record]}}