Andi Crew Andi Crew - 9 months ago 29
MySQL Question

How to display a cell value MySql Yii2?

I need to display value from db in my view file.

For example in my

view/index.php
(I need to do it in view)

<?=
Yii::$app->db->createCommand("SELECT adress FROM comp WHERE name = in_tk")->execute();
?>


So it return
0
or
1
.
0
if returns
0
row.
1
or more if returns
1
or more row. But I need to display value of a row.
For example in db:
adress = 205
. That sql will display
1
.

What yii2 method I need to do to display value of the cell?

Answer Source

Use queryAll instead execute to get all rows.

<?= 
    $rows = Yii::$app->db->createCommand("SELECT adress FROM  comp  WHERE name = in_tk")->queryAll(); 
?>