Model Finbysql()

Hi Guys,

recently I just use MyModel::model()->findBySql(); and I can retrieve the data just like what i query.

Now I wonder why there is another method in retrieve data like findbyPk, using Criteria, etc, when there is method like findBySql() :blink:

Because findBySql() requires that you write a query, where active record abstracts that away. It’s also much easier to extend or modify your criteria when you use a dedicated object, rather than trying to do so with a string of SQL.

An additional advantage is that the criteria based methods handle parameterization for you, so you reduce the risk of unintentionally introducing an SQL injection vulnerability.

:D thank you for explain sir