如果 Drupal 的 user_save() 失败会发生什么?

发布于 2024-09-27 04:13:37 字数 425 浏览 0 评论 0原文

我使用的是 Drupal 5.x,我正在尝试使用调用 drupal_bootstrap() 的脚本向站点添加新用户。生成用户名、电子邮件、密码和角色数组后,我创建新用户,如下所示:

$newuser = array( 'name' => $username, 'mail' => $email, 'status' => 1, 'pass' => $password, 'roles' => $roles);
$user = user_save('', $newuser);

我知道使用此代码我可以测试 user_save()< 返回的 $user 对象/code>,但是如何测试用户是否已正确创建和插入?我是否必须查询数据库来测试用户是否创建成功?

I'm on Drupal 5.x and I'm trying to add new users to the site using a script that calls drupal_bootstrap(). After generating the username, email, password, and role array, I create the new user like so:

$newuser = array( 'name' => $username, 'mail' => $email, 'status' => 1, 'pass' => $password, 'roles' => $roles);
$user = user_save('', $newuser);

I know that with this code I can test the $user object returned by user_save(), but how do I test if the user was created and inserted correctly? Do I have to query the database to test if the user was created successfully?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍风燃霜 2024-10-04 04:13:37

在 drupal 5 中,很难看到它像在 drupal 6 中一样失败。但是由于它从数据库返回一个新的用户对象,您可以检查它以查看数据是否正确保存。因此,如果您尝试插入用户但失败,它将返回 FALSE。

In drupal 5 it's not easy to see it it fails like in drupal 6. But since it returns a fresh user object from the db, you can inspect it to see if the data was saved properly. So if you try to insert a user and it failed, it will return FALSE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文