YII学习,yii
CONFIG
tablePrefix 设置表前缀
MODEL
设置与MODEL关联的表
public function tableName(){
return {{%table_name}} 表前缀加表名格式
}
分页:
use yii\data\Pagination;
$Page = new Pagination(['totalCount' => 总条数,'pageSize'=>每页显示数量]);
查询:
必须有与数据库名对应的model
Model名::find()->where(条件['status'=>1]);
$tombList
->offset($Page->offset分页)
->limit($Page->limit分页数量)
->all();
->all(); 查询全部
->one(); 查询一个
->count(); 查询数量
->average(字段); 查询平均值
->min(字段); 查询最小值
->max(字段); 查询最大值
->scalar(); 查询第一行第一列的值
->column(); 查询所有结果第一列的值
->each(数量); 反复查询结果,处理内存溢出现象
删除
Yii::$app->db->createCommand()->delete('表名','条件')->execute();
修改
Yii::$app->db->createCommand()->update('表名',修改字段['status'=>1],'条件')->execute();
添加
Yii::$app->db->createCommand()->insert('表名',数据)->execute();
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn