Binding a string value

Dear all,

I’m having a problem binding a string value to the sql. I have to bind lang value to the sql, but it doesn’t seem to fit in as I don’t get the required result. I need to have a query like ... AND lang='en' but when I bind the string to the sql, I have written '... AND lang=:lang', array(':lang'=>Yii::app()->language). However, it doesn’t work. How can I solve the problem?

Any help is highly appreciated.

Best Regards

post your code where you have added language filteration.

Please share your code to get a appropriate result.

Sorry, for not posting the code which caused confusion. Below is the code:

$results->select(', pl.l_title')

->from('post p1')

->leftjoin('postLang pl', ' AND pl.lang_id=:lang', array(':lang'=>(string)Yii::app()->language))

->where('p1.parent_id = :mid', array(':mid'=>(int)$menu_id));

I get result set but with empty values which is, I guess, because of string binding.

Best Regards

Ok if you thik that it is due to string binding problem then try to bind data something like this.



lets see what happen


I don’t think you need to cast Yii::app()->language to a string, it already is.

Anyway, I believe you have syntax errors, your code should be

$results->select(', pl.l_title')

->from('post p1')

->leftjoin('postLang pl', ' AND pl.lang_id = ":lang"', array(':lang'=>Yii::app()->language))

->where('p1.parent_id = :mid', array(':mid'=>(int)$menu_id));

PS What are the odds you chose p1 and pl as alias names, very similar in a monotype font :D

Edit: Jayant answered first :)


Thank you, guys.

bennouna, I have tried your version but I got the below error:

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. The SQL statement executed was: SELECT `p1`.`id`, `p1`.`title`

FROM `post` `p1`

LEFT JOIN `postLang` `pl` ON AND pl.lang_id=":lang"

WHERE p1.parent_id = :mid

jayant, your version also didn’t work.

PS. bennouna, don’t know. :) I’ll try to use a more reasonable alias names.

ohh no porbs…;)but i will recommend you to always use Cdbcriteria for this kind of work.Which provide you more secure way.