php - RedBeanPHP findAll 只返回最后一项

标签 php mysql findall redbean

我无法让 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 表:
tstampval

我必须在运行 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/

相关文章:

php - MySQL GROUP BY 优先考虑某些行

php - 将音频文件长度保存在数据库中

MySQL检测字段是否为空

python - 使用 re.findall 在正则表达式中捕获命名组

php - Laravel Datatable ManyToMany 与多个表的关系

php - 如何使用多个输入更新模型列

python - PyMySQL 一次查询中的不同更新?

php - 为什么将值传递给 PHP 函数然后将其转义并返回是不安全的

python - 如何查找 bs4 的所有字符串?

python - 如何使用 Beautiful Soup 的 find() 代替 find_all() 以获得更好的运行时间