Problems with LIKE in AR

Hello again,

I am working with AR and MySQL and I have a method that performs the following query:



<?php


protected function getResults($search)


{


   $clients = Client::model()->findAll(array(


			'select'=>'clientName',


			'condition'=>'clientName LIKE %:name%',


			'params'=>array(':name'=>$search),


		));


   return $clients;


}


But the following error is thrown:



CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%'mus'%' at line 1





Note:mus in the error information is the string passed in $search.


In MySQL, the correct sintax for the LIKE with an string is LIKE '%string%' and not '%'string'%'.

But the AR makes in that last way as we can see in the error.

Please, any other way to do this?

I've solved the problem doing this:

<?php

protected function getResults($search)

{

  $clients = Client::model()->findAll(array(

        'select'=>'clientName',

        'condition'=>'clientName LIKE :name',

        'params'=>array(':name'=> '%'.$search.'%'),

      ));

  return $clients;

}

Perfect!!! thanks…