[development] Insert users from script?
Matt West
mjw at our-hometown.com
Wed Dec 2 23:08:44 UTC 2009
Gastón,
You can do this programmatically by creating a separate script that
bootstraps Drupal. Something like:
if (($handle = fopen("file.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
// Set vars to the appropriate indexes from the .csv, you'll
need to customize this
list($user, $pass, $mail) = $data;
// Create the user array
$new_user = array(
'name' => $user,
'pass' => $pass,
'mail' => $mail,
'status' => 1,
'init' => $mail,
);
if(!user_load($new_user)) { // Make sure the user doesn't
already exist
// If you want to assign a role
$roles = user_roles();
$new_user['roles'] = array(array_search('your_roll_name',
$roles) => 1);
// Save the user
$new_user = user_save(null, $new_user);
}
}
fclose($handle);
}
On Dec 2, 2009, at 5:38 PM, Gastón Pablo Pérez wrote:
> Hi all
>
> I have data for several persons in an excel file and i would like to
> convert all of these people in users in my drupal 6. Somebody knows
> how can i do this? The idea is that not to have to create the users
> one by one, maybe i would have to make an sql script to include the
> users in one time, but i don't know in which tables I have to
> include the data and some other things for example, how have i to
> set the password? (this is encrypted in the database field)
--
Matt West
Software Developer
Our Hometown, Inc
mjw at our-hometown.com
More information about the development
mailing list