SqlRecordset and Filters
miSqlRecordset reads a collection of records from the database. It supports filters, can sort, group and can join multiple tables.
Get all records:
<?php
$recordset = new miSqlRecordset('Contacts');
$records = $recordset->getAllRecords();
?>
Using filters:
<?php
$recordset = new miSqlRecordset('Contacts');
$recordset->addFilter(new miSqlFilterEqual('ContactName', 'John Smith'));
$recordset->getAllRecords();
?>
Join two tables example:
<?php
$recordset = new miSqlRecordset('Contacts');
$recordset->addJoinCondition('INNER', 'Users', 'ON Users.UserID = Contacts.UserID');
?>
Get the number of records and retrieve the last 10:
<?php
$recordset = new miSqlRecordset('Contacts');
$numRecords = $recordset->getRecordsCount();
$records = $recordset->getRecordsByIndex($numRecords-10, 10);
?>
Alternative way to retrieve specific records:
<?php
$recordset = new miSqlRecordset('Contacts');
$recordset->setRecordsLimit(10, 5); // Retrieve 5 records, starting from 10th
$records = $recordset->getRecords();
?>