1
$use = Yii::app()->db->createCommand()
        ->select('name')
        ->from('user','registration')
        ->where('user.id=registration.user_id')
        ->queryRow();

If I unload MySQL with cmd, this command goes in Yii I was confused, I tried to change but it was still wrong.

2

2 Answers 2

1

You are trying to use the old school pre ANSI-92 implicit join syntax, and I'm not sure that Yii supports that. Intsead, try using the modern explicit join syntax:

$use= Yii::app()->db->createCommand()
    ->select('u.name')
    ->from('user u')
    ->join('registration r', 'u.id = r.user_id')
    ->queryRow();
2
  • what if I add a place with user.id = "1" it's like ->where('user.id = 1')
    – kagami
    Oct 11, 2018 at 4:37
  • @kagami Yes, I think you can use ->where('u.id = 1') in this case, because we have defined an alias earlier. Oct 11, 2018 at 4:40
1

You should use array if you want to pass multiple tables to from().

$use = Yii::app()->db->createCommand()
    ->select('name')
    ->from(['user', 'registration'])
    ->where('user.id=registration.user_id')
    ->queryRow();

Alternatively you could pass them as string:

$use = Yii::app()->db->createCommand()
    ->select('name')
    ->from('user, registration')
    ->where('user.id=registration.user_id')
    ->queryRow();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.