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

so I can search for specific values ​​by doing

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

however, what should I do if I want to combine a partial value?
right now, I resorted to writing the query myself, a la:

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

This is how I do a SQL type search:

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

'like' is a keyword.

This will create a query like:

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

Hope this helps.

+7
source

Source: https://habr.com/ru/post/908685/


All Articles