Jump to content

Just trying to move some data from 1 table to another


timcadieux

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='';

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.