Simple question here, From a computing and 'civicrm correctness' point of view, is using SQL (via CRM_Core_DAO::executeQuery or similar) or using the API ( civicrm_api3('Contact', 'create', $params)) better? Thanks, V

2 Answers 2


Generally, it is wisest to always use the API. Many necessary updates actually touch multiple tables and the API takes care of it nicely. This is especially true with financial updates. The API also encapsulates the database structure so as to effectively hide any database structure changes that may happen over time.

IMHO, pretty much the only time that SQL might be called for is if you are doing a huge bulk update wherein using the API would take excessively long.


Agree, the API is decidedly the best way as it does multiple stuff and should continue to function over upgrades when there are database changes. I only use SQL when either the API does not do what I need, with custom data because it is easier most of the times or when doing bulk stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.