phpBB forum - Restore a deleted user

Not about Bali, uhhh, maybe a bit :)
After some experimenting it can be done, if you can recreate the user record in the user table, using the same ID.

Then you have to “reconnect” the user with the posts and topics, this means changing the posts and topics which now are made by a “Guest” and linking them with the recreated user.

Here is the code, assuming the users had (and has again) a user_id of “4″ and the user name is “ubud_expat”.

$host=”localhost”;
$user=”user”;
$password=”passw”;
$dbname=”your_db”;
$link=mysql_connect ($host, $user, $password);

$nr_posts = 0;

$query = “SELECT * FROM `phpbb_posts` WHERE `poster_id` = -1 AND `post_username` = ‘ubud_expat’”;

$result=mysql_db_query($dbname, $query, $link);

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

$queryz = “SELECT * FROM `phpbb_topics` WHERE `topic_first_post_id` = $Row[post_id] AND `topic_poster` = -1″ ;
$resultz=mysql_db_query ($dbname, $queryz, $link);
$num_rows = mysql_num_rows($resultz);

if ($num_rows) {
print $Row[post_id] . ” - “;
$tRow = mysql_fetch_array($resultz);
$queryz = “UPDATE `phpbb_topics` SET `topic_poster`=’4′ WHERE `topic_id` = $tRow[topic_id]” ;
$resultz=mysql_db_query ($dbname, $queryz, $link);
}

$queryz = “UPDATE `phpbb_posts` SET poster_id=’4′ WHERE `post_id` = $Row[post_id]” ;
$resultz=mysql_db_query ($dbname, $queryz, $link);

$nr_posts = $nr_posts + 1;

}

$queryz = “UPDATE `phpbb_users` SET `user_posts` = $nr_posts WHERE `user_id` = 4″ ;
$resultz=mysql_db_query ($dbname, $queryz, $link);

mysql_close ($link);

Thats It!

Bookmark at:
StumbleUpon | Digg | Del.icio.us | Dzone | Newsvine | Spurl | Simpy | Furl | Reddit | Yahoo! MyWeb

4 Responses to “phpBB forum - Restore a deleted user

  • 1
    Dave C
    March 3rd, 2008 09:04

    I am trying to restore a PHPBB user and came across this. I have recreated the user in my table. Where do I put the above code to relink the guest posts? Thanks!

  • 2
    Bert
    March 3rd, 2008 09:35

    You just put it in a separate php file and run it…. (Then delete it again)

  • 3
    Dave C
    March 4th, 2008 02:03

    Ah, that makes sense. I’m new at this. I created a text file with that code and changed my user name and ID info. Is there anything else I need to change? I tried saving this text file as “changeguest.php” and uploading it to the root directory of my board but when I try to run it from a web browser it says the file can’t be found. If you have any tips I’d appreciate it. Thanks!

  • 4
    Bert
    March 4th, 2008 05:29

    If its not there, its not there…. ? Have any funny rewrite rules?

    If you have found it, try a dry run first by “remarking” the lines starting with “$resultz=”, you will see some numbers come by if it works…. The go for it without the “remarks”…

Leave a Reply

You must be logged in to post a comment.