使用redbeans php进行sql查询
嗨,我刚刚开始使用 redbeans ORM。我按照文档并尝试执行这样的查询
$thebean=R::find("users","id>2");
,然后我循环如下:-
foreach($thebean as $bean){
echo $bean->username;
}
但是我发现,即使 users 表包含超过 100 条数据,上述查询也只会获取最后的数据。例如:如果我有用户 1 到 100。我只获取 id=100 的用户。有人可以告诉我我可能做错了什么吗?
Hi I am just beginning to use redbeans ORM. I followed the docs and tried doing a query like this
$thebean=R::find("users","id>2");
and then I loop through like:-
foreach($thebean as $bean){
echo $bean->username;
}
However I find that if the even if the users table contains more than 100 data, the above query only fetches the last data . for eg: if I have users 1 to 100. I only get the user with id=100. Can somebody please tell me what I might be doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可能是字段类型的问题?您是否尝试过:
$thebean=R::find("users","id>'2'");
?Could be a problem on the type of field? Are you tried with:
$thebean=R::find("users","id>'2'");
?难道是你的语法不正确?我没有使用 Redbean 的经验,但你可能想做这样的事情:
无论哪种方式,当你执行以下操作时,你的结果是什么?它会返回所有用户还是仅返回一个用户?
Could it be that your syntax is not correct? I have no experience with Redbean, but you might want to do something like this:
Either way, what is your result when you do the following? Does it return all your users or just one?
看来是id字段的问题。使用 tableformatter 选项解决了它。
Seems that it was a problem with the id field. Solved it using tableformatter option.
您必须在查询中使用“findAll”。例如:
那么你可以做你的标准 foreach:
You have to use "findAll" on the query. So for example:
then you can do your standard foreach: