Yii框架操作AR/DAO-Delete篇

数据库表

Yii框架操作AR/DAO-Delete篇_第1张图片

Delete()

直接删除一条存在的AR,使用方法:

Manage::model()->findByPk($id)->delete();

deleteAll(mixed $condition='', array $params=array ( ))

直接删除符合条件的数据

eg.

$id  = ‘1,2,3,4,5’;

Manage::model()->deleteAll(“id in ($id)”);

支持标准SQL

$criteria  = new CDbCriteria();

$criteria->compare(‘id’,$id);

Manage::model()->deleteAll(criteria);

deleteByPk(mixed $pk, mixed $condition='', array $params=array ( ))

id 必须是主键,不是主键的话要在model设置

eg.

$Id = 5;

Manage::model()->deleteByPk($id);

$id = array(1,2,3,4,5);

manage::model()->deleteByPk($id,'name=:name',array(':name'=>'menu'));

删除主键是12345的菜单

 

DAO

delete(string $table, mixed $conditions='', array $params=array ( ))

eg.

$id = ‘1,2,3,4,5’;

$name = ‘menu’;

$state = Yii::app()->db->createCommand()->delete(‘manage’,”name = $name AND id in( $id )”);

 

你可能感兴趣的:(yii,delete)