[CiviCRM] How to debug SQL query in CiviCRM?

| | 1 min read

When I was calling CRM_Core_DAO::executeQuery() it gave error. I don't have any idea what went wrong. Not sure whether the SQL statement was correct or not. After searching for some time I found one function, composeQuery() in CRM_Core_DAO. It can be used to verify SQL query.

echo CRM_Core_DAO::composeQuery($sql, $params);

This will display the exact SQL Query which is going to run on the database. SO from that we can identify whether there is any issue in the query or not.