我使用Yii MVC来开发代码,我有一个代码,但是没有用;
我找不到错误,也许你们可以;
$sql = "
select extension
from file_extension
where status = :status and extension in ('" . $extensions . "');
";
$status = FileExtension::ACTIVE_STATUS;
$cmd = Yii::app()->getDb()->createCommand($sql);
$cmd->bindParam(":status", $status, PDO::PARAM_INT);
$arrObj = $cmd->queryAll();
当我使用print_r($arrObj);
时,我得到array()
为什么我没有得到结果?
经过一些工作,我发现我的查询是:
选择扩展名
from file_extension
where status = :status and extension in ('gif
','pdf
','chm
');
由于换行和空格,我的sql查询失败;
我该怎么做才能获得:
选择扩展名
from file_extension
where status = :status and extension in ('gif','pdf','chm');
答案 0 :(得分:1)
尝试:
$extensionList = Yii::app()->db->createCommand()->select('extension')
->from('file_extension AS fe')
->where("fe.status = :status AND fe.extension IN ('gif','pdf','chm')", array(':status' => FileExtension::ACTIVE_STATUS))
->queryAll();