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



Meet so Meet. C plusplus I-PLUS....
原文地址:https://www.cnblogs.com/iplus/p/4490007.html