yii 利用query 对数据库的操作

$connection = Yii::app()->db;
$sql="SELECT * FROM `express_template`  WHERE `ec_id`=$ec_id";
$command = $connection->createCommand($sql);  
$result = $command->queryAll(); 
$imgAddress = YiiBase::getPathOfAlias('webroot').'/static/ship_tpl_bg_imgs/'.$result[0]['bg'];
@unlink($imgAddress);


上面的操作是 将表中的字段给读出来,然后执行删除文件的操作。


$sql="UPDATE `express_template` SET `bg`='".$name."' WHERE`ec_id`=$ec_id";
$command = $connection->createCommand($sql);
$command->execute();
执行更新数据表中一个字段的功能,$command->execute() 返回的结果为1或者0



posted @ 2012-02-22 11:48  夏至冬末  阅读(162)  评论(0编辑  收藏  举报