Help With Simple Query Using Find

Here is my query




$client=new Client;

                $client=Client::model()->find(array(

                    'select'=>'id',

                    'condition'=>'sub_domain=:sub_domain', 

                    'params'=>array(':sub_domain'=>$this->domain[0])

                ));



In my db the field ‘sub_domain’ is a varchar. Here is the part I can’t figure out. When


$this->domain[0]

is an integer the query works and returns the matching record. When it is a word such as ‘mysub’, then it does not find the matching row and returns a NULL.

Please advise fellers

Does it have anything to do with the way I am using single quotes in my find() ?

Hi,

You can write this some thing look like this.


        $criteria = new CDbCriteria;

 	$criteria->select = 'id';

 	$criteria->addCondition("sub_domain LIKE '%sub_domain%'");

        $criteria->params=array(':sub_domain'=>$this->domain[0]); 

	$resultSet    =    Client::model()->find($criteria);

	print_r($resultSet);

What is wrong with the way I was doing it. It seems as though the query constructed is


SELECT id

FROM client

WHERE sub_domain = sample_data

Instead of the way I need it, like this


SELECT id

FROM client

WHERE sub_domain = 'sample_data'

It doesn’t seem to be passing the data as a string to the query. The reason I think so is because if sample_data = 1, then it returns the correct result. But if sample data is “wow”, then it doesn’t find the record.