insert
$row = Yii::app()->getDb()->createCommand()->insert('goods', array(
'good_name' => $goods_name,
'good_type' => $goods_type,
'price' => $price,
'buy_nums' => 0,
'commit_nums' => 0,
'create_time' => time(),
));
select 单表查询
$goodsTypes = Yii::app()->getDb()->createCommand()
->select('type_id, type_name')
->from('goods_type')
->where('status=1')->queryAll();
连表查询
$goods = Yii::app()->getDb()->createCommand()->from('goods g')
->select('g.good_id, g.good_name, gt.type_name, g.price, g.buy_nums, g.commit_nums, g.create_time')
->join('goods_type gt', 'g.good_type=gt.type_id')
->where('g.`status`=1 and gt.`status`=1')
->order('g.create_time desc')
->queryAll();
delete
$row = Yii::app()->getDb()->createCommand()
->delete('goods', "good_id=:good_id", array(
':good_id' => $goods_id,
));
update
$row = Yii::app()->getDb()->createCommand()->update('goods', array(
'good_name' => $goods_name,
'good_type' => $goods_type,
'price' => $price,
), "good_id=':goods_id",array(':goods_id'=>$goods_id));