1 ==================查询================== 2 $data = Yii::app()->db->createCommand('select * from admin where id between 1 and 10')->query();//执行一个非查询的sql语句 3 $data = Yii::app()->db->createCommand('select * from admin where id between 1 and 10')->queryAll();//返回多行数据 4 $data = Yii::app()->db->createCommand('select * from admin where id between 1 and 10')->queryRow();//返回一行数据 5 $data = Yii::app()->db->createCommand('select id from admin where id between 1 and 10')->queryColumn();//返回多个指定字段的值 6 $data = Yii::app()->db->createCommand('select id from admin where id between 1 and 10')->queryScalar();//返回一个指定字段的值 7 8 ==================新增================== 9 $insert = Yii::app()->db->createCommand()->insert('admin', ['id' => 1, 'name' => '你好']); 10 $insertId = Yii::app()->db->getLastInsertID();//获取插入数据的主键ID 11 $insert = Yii::app()->db->createCommand()->batchInsert('admin', ['id', 'name'], [1, '你好'], [2, '你好'], [3, '你好']); 12 13 ==================修改================== 14 $update = Yii::app()->db->createCommand()->update('admin', ['name' => '你好呀'], 'id = 1');//修改admin表,id = 1 name的值为'你好呀',set name = '你好呀' where id = 1 15 16 ==================删除================== 17 $delete = Yii::app()->db->createCommand()->delete('admin', 'id = 1');//删除admin表id = 1的数据