Jump to content

Recommended Posts

Ok, so I have need to move some data from one table to another every so often. I use the below code to simply Truncate the target table and then copy a fields from the Source table over. I only have 29 000 or so rows and I've done this type of thing before. My issue is that it's quite slow and when the Count reaches somehwere around 7000 or (easily 4-5minutes), the count seems to start back over at Zero, as though it were looping or something??

 

ini_set("memory_limit","256M");
set_time_limit(3000);
echo "Please wait as the tables are Truncated then Synchronised.";

mysql_connect($db_host,$MySqlUN,$MySqlPW);
@mysql_select_db($database) or die( "Unable to select databases");
$query =" SELECT ID, Surname, Initials, Forenames FROM MAIN ";

$TruncateME = mysql_query("TRUNCATE tblsearchtable ") or die ('Failed to Query Database' . mysql_error()); 

//TIME TO REBUILD THE TABLE FROM THE MAIN DB
$result = mysql_query($query) or die($query);
 while ($row= mysql_fetch_array($result)) {
  // Update the DB fields with the Amended content
  $sqlStatement = "INSERT INTO tblsearchtable

	   (ID, Surname, Initials, Forenames)
	  VALUES
	   ( '".mysql_real_escape_string($row['ID'])."',
	    '".mysql_real_escape_string($row['Surname'])."',
	    '".mysql_real_escape_string($row['Initials'])."',
	    '".mysql_real_escape_string($row['Forenames'])."'
	   )"; 

  // Step 4: MySQL Query 
  //echo $sqlStatement;
  $NEWresult = mysql_query($sqlStatement) or die ('Failed to Query Database' . mysql_error()); 
 }

  //Close the db connection
  mysql_close();
  $query='';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.