Hi guys,
Am using RedBeans ORM in PHP,
Today only am going through the RedBeans ORM, i think RedBeans is the Very simple to manage database.
But am getting doubt at which is better to use either rows(queries) or beans.

`$sql = 'SELECT author.* FROM author 
        JOIN club WHERE club.id = 7 ';
    $rows = R::getAll($sql);
    $authors = R::convertToBeans('author',$rows);`



Plz explain me why we need to convert again to Beans..
Member Avatar

LastMitch

Plz explain me why we need to convert again to Beans..

@Ramesh Konda

I don't understand your question?

What is the issue you are having?

It seem like you are testing out a query on a database.

`$sql = 'SELECT author.* FROM author
JOIN club WHERE club.id = 7 ';
$rows = R::getAll($sql);

here we are executing the query, and saving it in to $sql var.
and getting all values in to $rows right.
now to get the values we can use the $rows.
so again y we need to use

$authors = R::convertToBeans('author',$rows);` 

this(convertToBeans).

Member Avatar

LastMitch

so again y we need to use

@Ramesh Konda

What kind question is that?

You have to understand something, if you used any PHP framework, the framework itself has it own language and tags.

Did read this yet:

http://www.redbeanphp.com/welcome

The reason you ask this question because you don't understand how to used that language even though it's in PHP.

You need to post this question over there. The is reason is very simple.

I didn't write that code, RedBean did. They have a forum there.

Does that make sense?

thanks for u r replay... i/ll post it in redbean forum...

Just to answer to the question, the getAll() method will return a multidimensional array so, if you want to print the results, you have to loop it as an associative array:

foreach($rows as $author)
{
        echo $author['first_name'];
}

When you apply the convertToBeans() method you get an array of objects:

foreach($authors as $author)
{
        echo $author->first_name;
}

Here you can see the source of the file that defines the method, i.e. OODB.php:

In your example you can spot the difference by using print_r over the variables $rows and authors. Bye!