phpmysqlredbean

How to display all records from a table with RedBeanPHP?


What is the RedBeansPHP equivelant for this code?

$sql = "SELECT * FROM user";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["name"]."<br>";
    }
}

I've read that I need to use

$user = R::findAll('user'); 

but I don't know how to use it.


Solution

  • $users = R::findAll('user');
    foreach ($users as $user){
        echo $user->name.'<br>';
    }
    

    http://www.redbeanphp.com/finding findAll section. If you are using latest RedBean.