如果 Drupal 的 user_save() 失败会发生什么?
我使用的是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 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.