我正在尝试在Yii v.1 Mysql中进行LEFT加入。 有alreday 4个表加入,我也想加入这个表。
$cmd = Yii::app()->db->createCommand();
$selectString .= "table2.dir_pic, table2.pic1, table2.pic2 , table2.pic3 ";
$cmd->select($selectString);
$cmd->from('table1');
$cmd->leftjoin('table2', 'table1.id=table2.user_entry_id');
$entries = $cmd->queryAll();
$this->render('index', compact('entries', 'model'));
它提供了一个CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.`dir_pic`, `table2`.`pic1`, `table2`.`pic2`, ' at line 1.
我在mysql(phpmyadmin)
中尝试了这个查询 SELECT table1.id,table2.dir_pic,table2.pic1,table2.pic2, table2.pic3 FROM
table1 LEFT JOIN table2 ON table1.id = table2.user_entry_id
它显示正确的输出。但是当我在Yii中尝试时不是。
答案 0 :(得分:0)
我找到了解决方案。实际上我在前一个$ selectString查询结束后错过了一个逗号(,)。