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 dat开发者_如何学运维abase to test if the user was created successfully?
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.
精彩评论