findBySql gave me syntax error but phpmyadmin didn't

I got syntax even though there wasn’t one


look for right syntax to use near


 'WHERE post_id = 1  AND category_id = 1' at line 1. 


The SQL statement executed was:

 WHERE  guide_id = 1 AND category_id = 1	

I used


Model::model()->findBySql($sql)

… the $sql u can see above.

I tried to run the sql that was executed directly in phpMyadmin and chive and got no errors, it returned the expected row.

solved it by using…


Model::model()->find('post_id=:post_id AND category_id=:cat_id',

array( ':post_id'=>$model->id,':cat_id'=>$id,

)); 



…instead but it is more code and more complex for absolutely no reason (in this case)

tested:

xampp

yii 1.1.9

windows 7

firefox

findBySQL isn’t expecting the data from your WHERE claus as the first parameter, it’s expecting a full query. You’re literally just trying to execute:


WHERE post_id = 1  AND category_id = 1

Which of course is invalid.