Question

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

Was it helpful?

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

OTHER TIPS

But your execute code doing two query instead one.

I think that it is better:

$sQuery = "UPDATE users SET username='Bojangles' WHERE id=24 "; R::exec( $sQuery );

imho

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top