Drupal 6 To Drupal 7 User And Password Migration | Xplantr

Drupal 6 to Drupal 7 user and password migration

Here is the code to migrate User & Password from Drupal 6 to Drupal 7. It works fine for me.

// Connect with mysql server

$mysql_server = $server;

// Server name

$mysql_userName = DATABASE_USER_NAME;

$mysql_password = DATABASE_PASSWORD;

$connection = mysql_connect($mysql_server, $mysql_userName, $mysql_password);

// Query

$query = "SELECT * FROM users";

$count = 0;

$result = mysql_db_query(DATABASE_NAME, $query) or die(mysql_error() . " " . $query);

while($row = mysql_fetch_array($result)) {

//if($count++ > 10) break;

if($row[uid] == 0 || $row[uid] == 1) continue;

//require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');

$new_password_hash = user_hash_password($row[pass], 11);

if($new_password_hash)

{$new_password_hash = 'U'.$new_password_hash;}

$data = array( 'uid' => $row[uid],//db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField()), 'name' => $row[name], 'pass' => $new_password_hash, 'mail' => $row[mail], 'theme' => $row[theme], 'signature' => $row[signature], 'signature_format' => $row[signature_format],  'created' => $row[created], 'access' => $row[access], 'login' => $row[login], 'status' => $row[status], 'timezone' => $row[timezone], 'language' => $row[language], 'picture' => !empty($row[picture])?1:0, 'init' => $row[init], 'data' => $row[data], );

drupal_write_record('users', $data);

}