Ionut Flavius Pogacian
Ionut Flavius Pogacian

Reputation: 4801

Yii createCommand not working

I use Yii MVC to develop code, and I have a code, that does not work;

I can't find the error, maybe you guys can;

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

when I use print_r($arrObj); i get array()

Why don't I get results?

after some work, I see that my query is like:

select extension from file_extension where status = :status and extension in ('gif ','pdf ','chm ');

and because of the line breakes and the empty spaces, my sql query fails;

what can i do to obtain:

select extension from file_extension where status = :status and extension in ('gif','pdf','chm');

Upvotes: 0

Views: 639

Answers (1)

Daniel Vaquero
Daniel Vaquero

Reputation: 1305

Try:

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

Upvotes: 1

Related Questions