Pre-packaged Redbean fetches only one (last) row

混江龙づ霸主 提交于 2019-12-11 15:04:13

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/5663020/pre-packaged-redbean-fetches-only-one-last-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!