Kohana 3.1 ORM:如何制作“where ... in”条款
感谢 Kohana 出色的文档,我不得不屈服于 SO。 ;)
希望这真的很简单:我正在尝试收集属于某个 ID 组的所有故事。我的代码如下:
$story_ids = '(12,56,99,213,319)';
$stories = ORM::factory('story')->where('id', 'IN', $story_ids)->find_all();
但是,这显然不起作用。我收到 MySQL 错误,因为查询中的 $story_ids
字符串两边加上了单引号。
编辑:我也尝试过将 $story_ids
作为数组传递,但后来我只是收到“500内部服务器错误”
是否可以执行我所要求的操作?
提前致谢。
Thanks to Kohana's excellent documentation, I'm having to resort to prostrate myself on SO. ;)
Hopefully this is really simple: I'm trying to gather all stories which belong to a certain group of IDs. My code is as follows:
$story_ids = '(12,56,99,213,319)';
$stories = ORM::factory('story')->where('id', 'IN', $story_ids)->find_all();
However, this is obviously not working. I'm getting a MySQL error because single-quotes are being put around the $story_ids
string in the query.
EDIT: I've also tried passing $story_ids
as an array, but then I just get a "500 Internal Server Error"
Is it possible to do what I'm asking?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 $story_ids 作为数组传递应该可以。
你用的 Kohana 版本是什么?
Passing $story_ids as an array should work.
What Kohana version do you use?
您是否忘记了 ->select() ?
另外,此处概述了两种方法 使用“IN”关键字:
我通常将 DB::Expr 方法与您正在做的事情一起使用。
Did you perhaps forget the ->select() ?
Also, here are two ways outlined here to use the "IN" keyword:
I typically use the DB::Expr method with what you're doing.