预打包的 Redbean 仅获取一行(最后一行)

发布于 2024-11-01 10:38:11 字数 793 浏览 1 评论 0原文

我想使用 http://www.redbeanphp.com。当我尝试以这种方式获得结果时..

require_once ('redbean/rb.php');
require_once ('config.php');

R::setup('mysql:host='.MYSQL_HOST.';dbname=mydb', MYSQL_USER, MYSQL_PASS);
$test = R::find('function', ' ID < 10 ');
foreach ($test as $val) echo $val->Class.'<br>';

输出如下:

Notice: Undefined index: id in rb.php on line 3686

Notice: Undefined index: id in rb.php on line 3686

Notice: Undefined index: id in rb.php on line 3686
value.of.class.field.from.function.table    // << prints only the 9th value

正如您所看到的,即使有 ID 1 到 xxx 的条目,我也只得到最后一行的结果。当我将 where 子句设置为 ID < 9 我只打印出第 8 行。

有什么想法吗,为什么?或者 redbean 的任何无配置替代品?

I'd like to use the pre-packaged one-file Redbean 1.3 ORM from http://www.redbeanphp.com. When I try to get a result this way..

require_once ('redbean/rb.php');
require_once ('config.php');

R::setup('mysql:host='.MYSQL_HOST.';dbname=mydb', MYSQL_USER, MYSQL_PASS);
$test = R::find('function', ' ID < 10 ');
foreach ($test as $val) echo $val->Class.'<br>';

the output is as follows:

Notice: Undefined index: id in rb.php on line 3686

Notice: Undefined index: id in rb.php on line 3686

Notice: Undefined index: id in rb.php on line 3686
value.of.class.field.from.function.table    // << prints only the 9th value

As you can see I get only the result of the last row even though there are entries for ID 1 to xxx. When I set the where clause to ID < 9 I get only the 8th row printed out.

Any ideas, why? Or any configless alternatives to redbean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入画浅相思 2024-11-08 10:38:11

RedBeanPHP 的 id 区分大小写,您需要使用 'id' 而不是 ID。或者您必须使用 Bean Formatter 来确保 RedBeanPHP 知道您想要使用 ID 作为主键:

http:// /www.redbeanphp.com/#/Custom_Keys

RedBeanPHP's id is case sensitive, you need to use 'id' instead of ID. Or you have to use a Bean Formatter to ensure RedBeanPHP knows you want to use ID as your primary key:

http://www.redbeanphp.com/#/Custom_Keys

烟火散人牵绊 2024-11-08 10:38:11

您可以将表的主键重命名为“id”,然后 Redbean 可以识别它。如果您不希望像这样更改架构,则必须格式化 bean 并相应地返回自定义 id:

class MyTableFormatter implements RedBean_IBeanFormatter{
    public function formatBeanTable($table) {
            return $table;
    }
    public function formatBeanID( $table ) {
             if ($table=="user") return "user_id";
            return "id";
    }
}

R::$writer->tableFormatter = new MyTableFormatter;
$user = R::find( "user" );

代码参考:https://groups.google.com/forum/#!topic/redbeanorm/weIEM8p71eQ

You can rename your primary key of your table to 'id', then Redbean can identify it. If you don't wish to change your schema like that then you have to format the bean and return the custom id accordingly:

class MyTableFormatter implements RedBean_IBeanFormatter{
    public function formatBeanTable($table) {
            return $table;
    }
    public function formatBeanID( $table ) {
             if ($table=="user") return "user_id";
            return "id";
    }
}

R::$writer->tableFormatter = new MyTableFormatter;
$user = R::find( "user" );

Code Ref: https://groups.google.com/forum/#!topic/redbeanorm/weIEM8p71eQ

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文