Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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%"');
like image 307
ton.yeung Avatar asked Feb 17 '12 07:02

ton.yeung


1 Answers

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.

like image 181
Housni Avatar answered Oct 11 '22 15:10

Housni