$contactId = 123; // ID of the contact record to retrieve $params = array(1 => array($contactId, 'Integer')); $result = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_contact WHERE id = %1", $params); if ($result->fetch()) { $contactData = $result->toArray(); // Process the data retrieved from the database in $contactData }
$params = array(1 => array('John%', 'String')); $result = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_contact WHERE display_name LIKE %1", $params); while ($result->fetch()) { $contactData = $result->toArray(); // Process each record retrieved from the database in $contactData }This example demonstrates how to retrieve multiple contact records from the database using the LIKE operator to search for records whose display names match a specific pattern. The fetch method is used in a loop to retrieve each record in turn, until there are no more records to retrieve. Package library: CiviCRM.