S
S
Sergey2015-05-22 15:12:51
MySQL
Sergey, 2015-05-22 15:12:51

How to do double select WHERE with DAO in Yii2?

There is a controller

public function actionIndex()
    {
$accountident = Yii::$app->user->identity->account;
        $users = $db->createCommand("SELECT * FROM transactions WHERE sender='$accountident' AND payee='$accountident'")->queryAll();
        
        $dataProvider = new ArrayDataProvider([
            'allModels' => $users,
        ]);
        
        return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);
 }

C AND doesn't output anything for some reason

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ivankomolin, 2015-05-22
@alekskondr

This means that there is no entry in the transactions table that you want to find
. In general, it is better to write queries in Yii in this form:
$users = $db->createCommand()
->select('*')
->from('transactions')
->where ('sender=:sender', array('sender' => $accountident))
->andWhere('payee=:payee', array('payee' =>$accountident))
->queryAll();
It will be safer.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question