0

我使用 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');

4

1 回答 1

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();
于 2013-08-26T08:52:56.057 回答