Search code examples
phpmysqlredbean

How to update a particular row using id in redbean php


I have database with table "users"

+------+--------------+----------+
|  id  |  username    | password | 
|  22  |  foo         |    foo   |
|  23  |  bar         |    bar   | 
|  24  |  world       |  world   |

I wanna update the username where id = 24

How can i do this using redbean without sequel queries


Solution

  • First, R::load the row into a bean:

    $user = R::load('users', 24);
    

    Then update your data:

    $user->username = "Bojangles";
    

    And finally save the user back to the table:

    R::store($user);
    

    Please be sure to read the manual in the future - an example of how to do this is on the homepage