0

我想使用来自http://www.redbeanphp.com的预打包单文件 Redbean 1.3 ORM 。当我尝试以这种方式获得结果时..

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的任何无配置替代品?

4

2 回答 2

2

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

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

于 2011-06-15T14:02:08.180 回答
0

您可以将表的主键重命名为“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

于 2014-02-22T02:06:33.480 回答