MyBB Community Forums

Full Version: Adding 2000+ users to the db
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Adding 2000+ users to the db

Heres the back ground

We were lucky enough to pick up a forum with over 2000 members. Its been closed a year but in its hey days it was very popular. We have moved servers, set up MyBB and the theme is being done Cool

The old db (phpbb very old version) was hacked and is not recoverable but the old admin saved all the user names and e-mail addys

I started adding them 1 by 1 and it took around 3 hours to do just 100 Rolleyes

The user names are just on a notepad txt file in the following format

uptime - bisho@ xyz.com
Wraith - wraith@ xyz.com
pixel - pixel@ xyz.com

etc etc

Is there an easier way to add all these users to the db?? Big Grin
I have a php-script that was succesfully used to import 20,000 users to our system. I could give this script to MyBB-team if they wanted to....or to anyone. But whoever wants to use it, has to be competent with PHP as it WILL NOT WORK AS IS!!! It is built for our system and our system has customfields in user-table as well as 2 junction-tables....so from a standard MyBB-setup where user data is basically stored in 2 tables (users, userfields), we have it in 4 tables as well as in some extra fields hard-coded into the user-table.
So if anyone wants to amend it to work on a standard MyBB...feel free....it basically imports a csv-file and allocates a random-password to each...if I remember right....btu I am not a coder...I just had it done for us for when we migrated data from xls-files into the system....

cheers,
Kimmo
With the Upcoming MyBB Merge System, you can import separate forums and merge them with your current.
I think his point was that the old forum was beyond repair and the only thing left was a file with a username and email
Yes thats correct, in a note pad txt format, like this

uptime - bisho@ xyz.com
Wraith - wraith@ xyz.com
pixel - pixel@ xyz.com

Over 2000 user names to add manually. Is there an easier way
<?php
$file = file('path-to-your-file-here');
foreach($file as $key => $line)
{
     $line = explode(' - ', $line);
     mysql_query("INSERT INTO ".TABLE_PREFIX."users (username,email) VALUES($line[0],$line[1])");
}
?>

that should work
I don't think that script will work, but it's the right idea. [Image: msn_tongue.gif]

You'd probably want to set a default password, and the usergroup, and the regdate... maybe some other stuff too.

Here's a modified version of the script that I tested, and it worked... there might be some issues though. It should probably use MyBB's new user datahandler, but I'm lazy.

Update: Every inserted user will get a random password, so they will have to use MyBB's Reset Password feature before they can log in.

<?php

$filepath = 'path-to-your-file-here';
$usergroup = '2';
$regdate = time();


$file = @file($filepath) or die("Failed to load file \"$filepath\"");

define('IN_MYBB', 1);
require_once './global.php';

foreach($file as $line) {
    if(strpos($line, ' - ') === false) {
        continue;
    }
    $line = explode(' - ', $line, 2);
    $username = $db->escape_string(trim($line[0]));
    $email = $db->escape_string(trim($line[1]));
    $password = md5(random_str(8));
    $db->query("INSERT INTO ".TABLE_PREFIX."users (username,password,email,usergroup,regdate) VALUES ('$username','$password','$email','$usergroup','$regdate')");
    echo "Inserted user: $username<br />\n";
}

echo "<br /><strong>Done.</strong>";

?>

Upload it in your admin CP directory for security, then request it with your browser.
Assigning a default password could be a mistake too - any user could login as another user and "take over" their account.

Leaving the password blank would force the user to use the lost password functionality in order to set a new password for their account.

Alternatively you could generate a random password for each user and email it to them within the import script.
that's what I had...a random password assigned
Hmm... random password... sounds good.

* WDZ updates script
Pages: 1 2