@
@
@Twitt2017-06-04 12:18:59
Yii
@Twitt, 2017-06-04 12:18:59

What is the difference between the two database approaches?

The question is very noobish, but I still can’t understand, I would really like to get an answer in an understandable language
In general: I write on the Yii2 framework, we can get data from the model using ActiveRecord like this:

News::find()->where(['moderate' => 1])->orderBy(['id' => SORT_DESC])->all();

This, as I know, is called ORM.
And you can get it like this:
$posts = Yii::$app->db->createCommand('SELECT * FROM news WHERE moderate =:moderate ORDER BY DESC')->bindValue(':moderate', 1)->queryAll();

And this, in my opinion, is DAO
. In my opinion, the first option is simply automatically more convenient in terms of syntax, it is easier to work with it, and there is no need to bother with bindValue, since the ORM takes care of all this. More recently, they said that working with a database using SQL is already a stone age
. So, please explain in what situations you generally need to use DAO when there is such a convenient thing as ORM? In any case, there are some differences, and I'm sure they are significant, but I still don't understand them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2017-06-04
@dimonchik2013

two facts are enough:
1) ORM fits very well into the object-oriented style, with all its goodies, including migrations
2) ORM execution speed is 20-500% (usually closer to the second digit) slower

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question