UBB.Dev
Posted By: Kristina A couple of general questions - 11/25/2003 6:19 AM
I'm trying to do something that seems on the outside like it would be simple. I need to archive some posts off of my main database and onto another one to try and speed things up for my forums. All I really need for it to do is to copy old posts onto another database. I can delete them manually once they are copied over. I don't have much experience writing php code. I do have some in VB and Lotus script. I have this so far: [] <?php require_once('Connections/db6.php');

mysql_select_db($database_db6, $db6);
$query_Recordset3 = "SELECT * FROM w3t_Posts WHERE B_Number = [$i]";
$Recordset3 = mysql_query($query_Recordset3, $db6) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);
$totalRows_Recordset3 = mysql_num_rows($Recordset3);


require_once('Connections/db1.php');
mysql_select_db($database_db1, $db1);
$query_insert = "
INSERT INTO w3t_Posts (B_Board,B_Parent,B_Main,B_Posted,B_Last_Post,B_IP,B_Subject,B_Body,B_Kept,B_Status,B_Approved,B_Icon,B_Reged,B_Poll,B_Replies,B_Topic,B_Convert,B_PosterId,B_AnonName,B_Sticky,B_ParentUser)
VALUES ('$Board_q','$Parent','$Main','$date','$date','$IP_q','$Subject_q','$BodySig','$Kept_q','$PStatus_q','$Approved_q','$Icon_q','$Reged_q','$PollName','0','$Topic','$convert_q','$posterid','$AnonName_q','0','$ParentUser')
";
$insert = mysql_query($query_insert, $db1) or die(mysql_error());

?> [/]

I've pirated some of this. Anyway, my main plan is to step through this using a do while loop and incrementing variable $i. Can I just set the variable $Board_q = B_Board etc.? I don't have any idea how arrays really work in php. Can I just load all of the posts I need into an array and move them at once instead of stepping through one record at a time? There are about 150,000 posts I need to move. Thanks for any help. I have some PHP books on the way but I would like to go ahead and get this working.
Posted By: dimopoulos Re: A couple of general questions - 12/08/2003 3:45 PM
Kristina,

If the two databases are in the same MySQL server then what you can do is:

INSERT INTO Database1.w3t_Posts (B_Board,B_Parent,B_Main,B_Posted,B_Last_Post,B_IP,B_Subject,B_Body,B_Kept,B_Status,B_Approved,B_Icon,B_Reged,B_Poll,B_Replies,B_Topic,B_Convert,B_PosterId,B_AnonName,B_Sticky,B_ParentUser)
SELECT B_Board,B_Parent,B_Main,B_Posted,B_Last_Post,B_IP,B_Subject,B_Body,B_Kept,B_Status,B_Approved,B_Icon,B_Reged,B_Poll,B_Replies,B_Topic,B_Convert,B_PosterId,B_AnonName,B_Sticky,B_ParentUser
FROM Database2.w3t_Posts

That will copy all the posts from one database/table to another. Now since you said that there are 150K records you will either need a tool like phpMyAdmin or direct shell access to your server.

The trick with moving posts and threads is that they are linked and you cannot just move one and get over with it, you will need to move its "children" i.e. the replies.

Also you might want to have a look at JoshPet's Mass Threads Move modification to make your life easier. This modification will move the threads from one board to another for archiving but if you see it you might get a better understanding on what is needed to move posts.

Finally what you can do is take a mysqldump of the currend database, restore it somewhere else (another database) and then delete the old threads.

Loading all the posts in an array is not a good idea since you will grab all the resources from the server - for sure.

I hope this helps
© UBB.Developers