Cdbcriteria Vs Querybuilder

Hello,

I have to make some filters, such as get persons who are in a given departement, and I was wondering about the best way to do it.

I espacially would like to know about the databases compatibility. I mean if tommorow I change from MySQL to SQLite, would my requests still run?

I found that about Query Builder:


It offers certain degree of DB abstraction, which simplifies migration to different DB platforms.

Is it the same for the CDbCriteria objects? Is it better?

If anyone knows a bit more about this subject, you’re welcom.

Thanks you

Have a nice day :)

Michaël S.

Hi Michaël,

Yii uses PDO (PHP Data Objects) to handle database access. Both DAO (using query builder) and AR (using db criteria) rely on PDO. And the differences between DBMSs (e.g. MySQL and SQLite) are handled in the level of PDO … to a certain degree. :) It is possible to write a db-specific code using PDO (and using DAO or AR).

As a practical consequence, I think there’s not so much difference between DAO and AR regarding this. If we avoid db-specific SQL syntaxes in our code, it will run on any DBMS that supports PDO.