查询:
// where 查询
$results = Test::find()->where(['name'=>'kataap'])->andwhere(['sex'=>1])->all();
// id > 10
$results = Test::find()->where(['>','id',10])->all()
// between
$results = Test::find()->where(['between','id',1,2])->all()
// like
$results = Test::find()->where(['like','name','kata'])->all()
// :id占位符
$results = Test::findBySql($sql,array(':id'=>'1 or 1=1))->all()
// 查询结果转换成数组
$results = Test::find()->where(['name'=>'kataap'])->aeArray()->all();
批量查询:
// 分批拿数据,每次拿20条
foreach( Test::find()->batch(20) as $tests){
print_r($tests);
}
添加数据:
$test = new Test;
$test->name = 'kata';
$test->sex = 1;
$test-save();
// 获取error
print_r($test->errors);
修改数据:
// save 修改
$test = Test::find()->where(['name'=>'kata'])->one();
$test->sex = 2;
$test->save();
// updateAll 修改
Test::updateAll(['sex' => 2], ['name' => 'kata']);
删除数据:
// 删除order_id = 1000001的数据
Test::deleteAll(['order_id' => 1000001]);
// 占位符 删除id > 10的数据
Test::deleteAll('id > :id', [':id'=>10]);
// 删除所有数据
Test::deleteAll();