$dao = CRM_Core_DAO::executeQuery('SELECT * FROM civicrm_contact'); $results = array(); while($dao->fetch()) { $results[] = $dao->toArray(); }
$currentDate = date("Y-m-d H:i:s"); $dao = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_event WHERE event_start_date >= '$currentDate'"); $results = array(); while($dao->fetch()) { $results[] = $dao->toArray(); }In both examples, the CRM_Core_DAO package library is used to connect with the database and retrieve records. The commonRetrieveAll function is used in conjunction with a SQL query to return the desired records.