1.查询结果转化数组 (对象在内存中占有量比数组高 where()后面加->asArray() 把对象转换成数组)
$results = Test::find()->where([‘between‘,‘id‘,1,2])->all(); //打印结果是对象
$results = Test::find()->where([‘between‘,‘id‘,1,2])->asArray()->all(); //打印结果是数组
2.批量查询 (循环查询,循环次数多,sql语句多,性能差|批量查询一次查询多条,减少循环次数,性能好,节省内存)
foreach(Test::find()->batch(20) as $tests) //每次查询20条数据给$tests
{
print_r(count($tests));
}
时间: 2024-10-18 10:54:01