Well, I'll give it a shot and ask here about a problem I have.

Discussion in 'PHP' started by Jackuul, Apr 8, 2007.

  1. #1
    I will quote my previous posts from other sites:

    >.>

    I hope someone here can indeed help me with this - a script to do this. I know it's somewhat complex but I could give you little green rep things that will probably be gray instead of green because I don't have the age on my account I would otherwise have had I been told about this site ages ago.
     
    Jackuul, Apr 8, 2007 IP
  2. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I found your post quite difficult to follow but as far as I can tell your problem is that you have a whole number of entries deleted from the table phpbb_users and you want to go through and restore them. You don't want to overwrite the users that still exist though.

    Is this right?

    I don't want to post something detailed up until I know as i've been using the MDB2 PEAR package to handle database interaction for so long that I've forgotten how the native functions work and that's probably what you want.
     
    streety, Apr 8, 2007 IP
  3. Jackuul

    Jackuul Well-Known Member

    Messages:
    2,972
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    180
    #3
    You got it down.

    That is exactly what I am trying to do - except there are more deleted users than existing users.

    I need to replace the deleted users with a dummy user, and I would like each dummy user to have the id number it corresponds with in the name. Like if User ID 444 is missing the script will make dummy444, and thus all the posts lost by that user through the incorrect deletion performed by the previous owner will be restored.
     
    Jackuul, Apr 8, 2007 IP
  4. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Then lets see what we can do . . .

    
    $x = 1;
    while($x < 3000) {
        $sql_query = "SELECT user_id FROM phpbb_users WHERE user_id = '$x'";
        $result = mysql_query($sql_query);
    
        if(mysql_num_rows($result) != 1) {
            $sql_insert = "INSERT INTO `phpbb_users` (`user_id`, `user_active`, `username`, `user_password`) VALUES ('$x', '0', 'Dummy{$x}', 'X')";
            $insert_result = mysql_query($sql_insert);
        }
    
        $x++;
    }
    
    
    PHP:
    It's not particularly elegant and is more resource intensive than it should be but it should get the job done and as you only need to run it once performance isn't a major concern.

    Remember that my memory of the native PHP functions is rusty so backup your data before giving it a try.

    I would also suggest you use something other than 'Dummy', as it isn't very flattering. Perhaps archive instead.
     
    streety, Apr 9, 2007 IP
  5. Jackuul

    Jackuul Well-Known Member

    Messages:
    2,972
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    180
    #5
    Thanks! I will try this on a test backup - and let you know how it goes.
     
    Jackuul, Apr 9, 2007 IP
  6. Jackuul

    Jackuul Well-Known Member

    Messages:
    2,972
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    180
    #6
    You are awesome.

    It worked!

    Thankyou Thankyou Thankyou! :)
     
    Jackuul, Apr 9, 2007 IP
  7. streety

    streety Peon

    Messages:
    321
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    First time as well. :)

    I surprised myself with that one.
     
    streety, Apr 9, 2007 IP