我无法让 findAll 函数返回比结果查询的最后一行更多的内容。我在 PHP 脚本上设置了 R::debug( TRUE )
,它清楚地表明返回的数据结果集中有 4 个结果。当我将查询直接输入 MySQL 时,输出的查询按预期工作,返回 4 行。
这是我的 PHP 代码:
<?php
require 'include/rb.php';
include 'include/config.php';
R::debug( TRUE );
echo 'test4<br>';
$returnpeople = R::findAll('breadline');
echo '<br>';
foreach ($returnpeople as $key => $bean) {
echo $bean->tstamp.'<br>';
}
print_r($returnpeople );
?>
breadline 是一个包含 2 个字段的 MYSQL 表:
tstamp
和 val
我必须在运行 PHP 5.3.3 的系统上部署我的代码,因此我已经完成了补丁。
我看到其他人也描述了这个问题,但他们使用了参数。即使在删除所有参数并调用 R::findAll('breadline');
之后,我仍然得到它。
即使在我设置为运行 PHP 5.3.3 的测试服务器上使用参数时,我也无法重现此错误。
最佳答案
关于红 bean website ,有一些要求:
Existing schemas
RedBeanPHP has been designed to build your database on-the-fly, as you go. Afterwards, you can manually change the schema to suit your needs (change column types, add additional indexes). Remember that the purpose of RedBeanPHP is to have an easy, configuration-less ORM. This can be achieved only by respecting certain conventions.
我假设您的表必须有一个 id
字段,因为在方法 convertToBeans
中,使用了 id
:
public function convertToBeans( $type, $rows )
{
$collection = array();
$this->stash[$this->nesting] = array();
foreach ( $rows as $row ) {
$id = $row['id'];
$this->stash[$this->nesting][$id] = $row;
$collection[$id] = $this->load( $type, $id );
}
$this->stash[$this->nesting] = NULL;
return $collection;
}
关于php - RedBeanPHP findAll 只返回最后一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133623/