2013-08-26 50 views
0

我使用Yii MVC開發代碼,並且我有一個代碼,這是行不通的;Yii createCommand不工作

我找不到錯誤,也許你們可以;

$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 ');

因爲線breakes和空的空間,我的SQL查詢失敗的和;

我能做些什麼來獲得:

選擇擴展 from file_extension where status = :status and extension in ('gif','pdf','chm');

+1

能不能介紹一下你所得到的錯誤詳細點嗎? –

+0

嘗試:Yii :: app() - > db-> createCommand($ sql); –

+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(); 
+0

這就是我發現的足跡空間;所以,是的,它向我提供瞭解決方案 –