Search code examples
phpyiiyii1.x

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'registration' in 'where clause' in Yii 1.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.


Solution

  • 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();