YII DAO增删改查

原创
2013/12/18 11:02
阅读数 836

简单的增删改查

$c = Yii::app()->db->createCommand()->insert('{{test2}}', array('name'=>'张三'));
$u = Yii::app()->db->createCommand()->update('{{test2}}',array('id'=>3,'name'=>'李四'));
$r=Yii::app()->db->createCommand("select * from {{test2}}")->query()->readAll();
$d = Yii::app()->db->createCommand()->delete('{{test2}}','id=:id',array(':id'=>3));


更新

$id = 26;
        $typename = '什么呀2';
        $model = Yii::app()->db->createCommand()                
                ->update('{{arctype}}',array('typename'=>$typename),'id=:id',array(':typename'=>$typename,':id'=>$id));



新增
$topid = 2;
$typename = '新增栏目';
$model = Yii::app()->db->createCommand()                
         ->insert('{{arctype}}',array('typename'=>$typename,'topid'=>$topid));



删除
$model = Yii::app()->db->createCommand()                
                ->delete('{{arctype}}','id=:id',array(':id'=>26));



查询
$model = Yii::app()->db->createCommand()
                ->from('{{archive}} arc')
                ->select('arc.id,arc.title,type.typename')
                ->join('{{arctype}} type','type.id=arc.typeid')
                ->where('type.id=:typeid',array(':typeid'=>7))
                ->order('arc.id desc')
                ->queryAll();




展开阅读全文
打赏
2
3 收藏
分享
加载中
更多评论
打赏
0 评论
3 收藏
2
分享
返回顶部
顶部