Yii::app()->db->createCommand($sql1)->queryAll() 没有返回整个表 [英] Yii::app()->db->createCommand($sql1)->queryAll() is not returning whole table

查看:25
本文介绍了Yii::app()->db->createCommand($sql1)->queryAll() 没有返回整个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$rows = Yii::app()->db->createCommand()->select('*')->from('states')->queryAll();

$rows = Yii::app()->db->createCommand()->select('*')->from('states')->queryAll();

上面的代码只返回第一行,而根据文档,它应该返回所有行.

above code returns only single first row, while according to documentation it should return all rows.

推荐答案

queryAll() 返回一个数组,你需要迭代以获得所有记录

queryAll() returns an array and u need to iterate in order to get all the records

foreach($rows as $row){
  //do something
}

这篇关于Yii::app()->db->createCommand($sql1)->queryAll() 没有返回整个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆