标签:des style blog color strong div log sp on
$customer=new Customer();//插入操作
$customer->name=‘小熊‘;
$customer->save();
//修改操作
$model=Customer::findOne(1);
$model->name=‘小洋‘;
$model->save();
/* --------------------修改指定条件集-------------------- */
Customer::updateAll([‘age‘=>24],[‘age‘=>18]); //将所有年龄为24的 修改为年龄 18
//删除
$model->delete();
Customer::deleteAll(‘age > :age AND gender = :gender‘, [‘:age‘ => 20, ‘:gender‘ => ‘M‘]);
//查询
/* like 查询 */
Customer::find()->andFilterWhere([‘like‘,‘name‘,‘洋‘]);
/* orderby 查询 */
Customer::find()->OrderBy([‘date‘=>SORT_DESC]);
/* 按主键id查询 */
Customer::findOne($id);
/* 多条件查询 */
Customer::find()->where([‘name‘=>‘小洋‘])
->andwhere([‘age‘=>24])
->all(); //查询返回全部
// ->one() 查询1个结果
// ->count() 获取数量
/* 多表联查 */ $model=new Customer(); $model->fiind()->join(‘LEFT JOIN‘,‘student‘,‘student.cid=customer.id‘) ->where(‘student.id‘=>\Yii::$app->user->id) ->andwhere(‘is_ok=1‘) ->one();
标签:des style blog color strong div log sp on
原文地址:http://www.cnblogs.com/sheapchen/p/3939710.html