Search code examples
phpmysqlfindallredbean

RedBeanPHP findAll only returns last item


I cannot get the findAll function to return more than the last row of the result query. I set R::debug( TRUE ) on the PHP script and it clearly says that there are 4 results in the returned data resultset. The query outputted works as expected, returning 4 rows, when I entered it directly into MySQL.

Here is my PHP code:

<?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 is a MYSQL table with 2 fields:
tstamp and val

The system I have to deploy my code on runs PHP 5.3.3 and as such I've done the patch.

I've seen other people describe this issue as well, but they used parameters. I'm still getting it even after removing all parameters and calling R::findAll('breadline');.

I have not been able to reproduce this error, even when using parameters, on my test server which I have set to run PHP 5.3.3.


Solution

  • On Redbean website, there are some requirements :

    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.

    I assume your table must have a id field because in the method convertToBeans, the id is used :

    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;
    }