S
S
Sergey2015-03-09 19:27:00
Yii
Sergey, 2015-03-09 19:27:00

How to select only some columns in yii2 and not the whole row from the database?

This is how all the data is taken and everything works:

$db = new database();
$rows = $db->find()->All();

I want to take only id and name.
This doesn't work, doesn't return what I expect:
$db = new database();
$rows = $db->find()->select('id','name')->All();

So too:
$db = new database();
$rows = $db->find('id','name')->All();

I removed all, did not help.
In docks and in Google I can not find the decision.
Already freaked out and pulled out the necessary ones from all the data in a cycle, but the govnokod does not give me rest.
How to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mick Coder, 2015-03-09
@butteff

Take 'id','name' in brackets []

$db = new database();
$rows = $db->find()->select(['id','name'])->All();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question