Inserting users from a phpbb2 database into drupal5/phpbb3

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by krisbfunk on December 24, 2007 at 3:50am

Please excuse me if I'm asking a terribly redundant question here, I read through the posts, but haven't found the answer. But I've just got the phpbb3/drupal5 mod working and am now wondering how to import about 85 users from an existing phpbb2 forum. Should I first upgrade it to phpBB3, then copy the user information over just as if I were moving from one installation to another without drupal?

If this has been posted elsewhere, please refer me to the location.

Thanks!

Categories:

Comments

I've done something similar,

Posted by arkepp on December 24, 2007 at 3:13pm

I've done something similar (merged three phpBB forums and copied the best user match), and I've heard of other people who have, but afaik nobody has provided any code for doing this.

My recommendation is to
1) Copy users from phpBB 2.x to Drupal (user id, username, password, email... all other fields can be replaced by defaults I think) and insert them into the approriate group.
2) Upgrade phpBB 2.x to 3.x
3) Increase the user id sequence in Drupal to avoid overlap with automatically inserted search engines in phpBB.
4) Test that Drupal with phpBB users works, and that phpBB 3.x works
5) Integrate the two, should be easy to figure out what parts of the instructions to follow and what to skip.

tables to export

Posted by krisbfunk on December 24, 2007 at 6:36pm

ok, thanks.. that makes sense.

But for #1) can you provide more detailed instruction on which tables to export from the phpBB 2.x mysql db, and how to insert them into Drupals mySQL db?

Say.. I run this Query on my phpBB2 db:
SELECT username, user_password, user_email FROM phpbb_users WHERE user_id > -1

end up with a dump like:
--
-- Dumping data for table phpbb_users
--
INSERT INTO phpbb_users VALUES ('username', 'encrypted-pass', 'email@gmail.com');

Then how do i get this data into the drupal_users table? Just not sure of the exact syntax.. I first have to select UID, pass and mail right? then insert those values.

Well, you'll need to check

Posted by arkepp on December 24, 2007 at 6:25pm

Well, you'll need to check the user_id > -1, since you can't have overlaps. Probably 1 instead of -1.

The SELECT looks okay, but you'll also need the userid.

Then look at the Drupal table to see what the same columns are called there, fix your SQL dump to match that. Finally, look at the existing users in the table and expand the INSERT statements with reasonable default values for the other columns.

Afterwards you'll need to update the entry for userids in Drupals sequence table and check the group table, probably add the converted userids there. I don't have time to check the tables or write that one out in full, sorry.

np, going to create a php

Posted by krisbfunk on December 24, 2007 at 8:20pm

np, going to create a php script to instert into the drupal db . will post results

should be able to export the sql fields into a flat file that can be read by php and auto insert the users into the database, while auto incrementing the uid, fairly easily.

here is what worked for me

Posted by krisbfunk on December 25, 2007 at 1:45am

ok.. seemed to be pretty straightforward. please excuse my horrible cut & paste php.. i know very little about it.

I ran this Query on the phpBB2 mysql db in phpmyadmin:

SELECT user_id, username, user_password, user_email FROM phpbb_users WHERE user_id > 1

Exported the results to CSV using these settings:

Fields Terminated by: ||
Fields enclosed by:
Fields escaped by:
Lines terminated by: AUTO
Replace NULL by:

the results looked like this:

uid1||username1||encrypted-pass1||email1
uid2||username2||encrypted-pass2||email2
uid3||username3||encrypted-pass3||email3

saved this to a .txt file called userdata.txt and uploaded it to the same server my drupal db is on
created a .php file called drupaluserupdate.php and uploaded it to the same directory with this in it: (the $status and $created were simply to create a created date that wasn't 38 years ago.. and an active account)

<?php
$link
= mysql_connect('localhost','database_user','database_password');
if (!
$link) { die('Could not connect to MySQL: ' . mysql_error()); } echo 'Connection OK ';
mysql_select_db('database_name') or die(mysql_error());

$fh = fopen("userdata.txt","r");

while (!
feof($fh))
{
$created = 1198469649;
$status = 1;

$str=fgets($fh,1024);
list(
$uid,$name,$pass,$mail)=explode("||",$str);

// Insert a row of information into the table
mysql_query("INSERT INTO drupal_users(uid,name,pass,mail,init,created,status) VALUES($uid,'$name','$pass', '$mail', '$mail', $created, $status) ") or die(mysql_error());

}

echo
'Flat File Data Inserted!';


mysql_close($link);
fclose($fh);


?>

ran it, checked the drupal db, seemed to work.. Do you see any issues with the way i did this?

I then updated the sequence table to 1000.. Is this it for the account data import aside frpm the groups?

Not sure why you're going

Posted by arkepp on December 26, 2007 at 4:31pm

Not sure why you're going via a .txt file, but that's okay, if the users are working then this should be all you need to do. I checked the groups again, doesn't seem like you need to do anything about that for regular users.

-Arne

well, only from txt because

Posted by krisbfunk on December 26, 2007 at 4:46pm

well, only from txt because i don't know the other possible solutions. it did work without much pain though, so i'm satisfied. thanks for the help. the board is converted and up and running ok with avatar and login features working between the two.

just realized

Posted by krisbfunk on December 26, 2007 at 6:15pm

i could have chose to export as SQL from the original phpBB2 db after running this query:
SELECT user_id, username, user_password, user_email FROM phpbb_users WHERE user_id > 1

and on the export screen checked "complete inserts" .. doing so, i would have got an output like:
INSERT INTO phpbb_users (user_id, username, user_password, user_email) VALUES(2, 'username1', 'encrypted-pass', 'email@email.com');

then ran a find/replace using a good text editor like editpad, inputing the drupal table information.. and came out with something like this:
INSERT INTO drupal_users (uid, name, pass, mail) VALUES(2, 'username1', 'encrypted-pass', 'email@email.com');

and use that to insert the values into the drupal db directly through phpmyadmin. hah. oh well! maybe it'll help someone else.

avatars

Posted by krisbfunk on December 26, 2007 at 8:46pm

actually weren't working, only new ones that had been uploaded.

so i had to transfer the avatars over from the default folder in phpbb3 (after changing to the new directory)

and update the drupal_users with the proper path to each avatar

phpbb

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /