Skip to content
  • totten's avatar
    CRM_Utils_SQL_Select - Allow fluent query execution · 77e74ae1
    totten authored
    When I first wrote `CRM_Utils_SQL_Select`, I was a bit dogmatic about
    loose-coupling and wanted the class to be entirely independent of the SQL
    runtime. But this is a bit annoying in usage and training.
    
    Before
    ======
    
    To build and execute query, you had to pass the rendered SQL to the execute
    function, eg
    
    ```php
    $select = CRM_Utils_SQL_Select::from('mytable')
      ->select('...')
    $dao = CRM_Core_DAO::executeQuery($select->toSQL());
    while ($dao->fetch()) { ... }
    ```
    
    After
    =====
    
    You can use more fluent style:
    
    ```php
    $dao = CRM_Utils_SQL_Select::from('mytable')
      ->select('...')
      ->execute();
    while ($dao->fetch()) { ... }
    ```
    
    And you can chain with other DAO functions like `fetchAll()` or
    `fetchValue()`.
    
    ```php
    $records = CRM_Utils_SQL_Select::from('mytable')
      ->select('...')
      ->execute()
      ->fetchAll();
    ```
    77e74ae1