Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    Sep 2003
    Location
    Sydney
    Posts
    114
    Member #
    3051
    I have a phpBB database which I am trying to convert to work with Joomla. I'm using a script someone has provided and it works fine...apart from one section - the message text.

    It doesn't give me an error or anything so I can only assume it is timing out.

    What I would like to do is split the query/migration of the message text into blocks.

    Here is the what is doing at the moment:

    Code:
    //Populate Messages_Text Table
    echo "<br />Populating Messages_Text Table...\n";
    
    $query="TRUNCATE TABLE `$joomla_db`.`{$joomla_dbprefix}fb_messages_text`";
    $result = mysql_query($query) or die("<br />Invalid query:<br />$query<br />" . mysql_error());
    
    $query="SELECT post_id, post_text FROM `$phpbb_db`.`{$phpbb_dbprefix}posts`";
    $result = mysql_query($query) or die("<br />Invalid query:<br />$query<br />" . mysql_error());  
    $mtext = array();
    $mpostid = array();
    while ($row = mysql_fetch_object($result)) { 
      $text = addslashes($row->post_text);
      $mtext[] = prep($text);
      $mpostid[] = $row->post_id;
    } 
    mysql_free_result($result); 
    
    for ($i=0; $i < count($mtext); $i++){
      $query="INSERT INTO `$joomla_db`.`{$joomla_dbprefix}fb_messages_text`"
        ." (mesid, message) VALUES"
        ." (".$mpostid[$i].", \"".$mtext[$i]."\")";
      $result = mysql_query($query) or die("<br />Invalid query:<br />$query<br />" . mysql_error());
    }
    
    echo "OK\n";
    Does anyone have any tips?

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    The problem is that you're loading everything into an array, which is stored in memory (ram). With big tables, that'll really kill you.

    You should iterate through and free memory after every record. That'll fix your problem.

    PHP Code:
    //Populate Messages_Text Table
    echo "<br />Populating Messages_Text Table...\n";

    $query="TRUNCATE TABLE `$joomla_db`.`{$joomla_dbprefix}fb_messages_text`";
    $result mysql_query($query) or die("<br />Invalid query:<br />$query<br />" mysql_error());

    $query="SELECT post_id, post_text FROM `$phpbb_db`.`{$phpbb_dbprefix}posts`";
    $result mysql_query($query) or die("<br />Invalid query:<br />$query<br />" mysql_error());  
    $mtext = array();
    $mpostid = array();
    while (
    $row mysql_fetch_object($result)) { 
      
    $text addslashes($row->post_text);
      
    $text prep($text);
      
    $query="INSERT INTO `$joomla_db`.`{$joomla_dbprefix}fb_messages_text`"
        
    ." (mesid, message) VALUES"
        
    ." (".$row->post_id.", \"".$text."\")";
      
    mysql_query($query) or die("<br />Invalid query:<br />$query<br />" mysql_error());

    mysql_free_result($result); 

    echo 
    "OK\n"

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    By the way, really the fastest way to do this would be to do a single INSERT... SELECT, like so:
    PHP Code:
    //Populate Messages_Text Table
    echo "<br />Populating Messages_Text Table...\n";

    $query="TRUNCATE TABLE `{$joomla_db}`.`{$joomla_dbprefix}fb_messages_text`";
    $result mysql_query($query) or die("<br />Invalid query:<br />{$query}<br />" mysql_error());

    $query="INSERT INTO `{$joomla_db}`.`{$joomla_dbprefix}fb_messages_text` (mesid, message)
            SELECT post_id, post_text FROM `
    {$phpbb_db}`.`{$phpbb_dbprefix}posts`";
    $result mysql_query($query) or die("<br />Invalid query:<br />{$query}<br />" mysql_error());

    mysql_free_result($result); 

    echo 
    "OK\n"
    I think that'll do it!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:33 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com