Search code examples
phpmysqlsqlitelithium

how to use LIKE with conditions in sqlite or mysql with lithium recordset


so I can look for concrete values by doing

        $recordset= Model::find('all', array(
            'conditions' => array(
                'condition' => $somevalue
            ) 
        ))

however, what do I do if I want to match on a partial value?
right now, I've resorted to writing the query myself, a la:

$abc = Connections::get('default')->
   read('SELECT * FROM myTable WHERE condition LIKE "%partial string%"');

Solution

  • Here's how I do an SQL 'like' search:

    $user = User::find('all', array(
            'conditions' => array(
                'first_name' => array('like' => '%yeun%'))
            )
    );
    

    'like' being the keyword, there.

    That would generate a query like:

    SELECT * FROM `users` AS `Users` WHERE (`first_name` like '%yeun%');
    

    Hope that helps.