如何在 redbean php 中使用 id 更新特定行


How to update a particular row using id in redbean php

>我有带有表"users"的数据库

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

我想更新用户名,其中 id = 24

如何在没有续集查询的情况下使用 redbean 来做到这一点

首先,将行R::load到一个 bean 中:

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

然后更新您的数据:

$user->username = "Bojangles";

最后将用户保存回表中:

R::store($user);

请务必在将来阅读手册 - 如何执行此操作的示例在主页上

但是您的执行代码执行两个查询而不是一个查询。

我认为它更好:

$sQuery = "更新用户设置用户名='Bojangles' 其中 id=24 ";R::exec( $sQuery );

恕我直言