Skip to content

Instantly share code, notes, and snippets.

@stefpe
Created February 27, 2019 15:01
Show Gist options
  • Save stefpe/645775bbc4a86a779627632121c65a6f to your computer and use it in GitHub Desktop.
Save stefpe/645775bbc4a86a779627632121c65a6f to your computer and use it in GitHub Desktop.
Simple script to copy by id from one to another db table
<?php
$con = mysqli_connect("host","user", "password");
mysqli_select_db($con, "dbname");
$stepSize = 100000;
foreach(range(1,50000000, $stepSize) as $step){
$sql = sprintf('insert into tmp_table select * from table where id >= %d and id < %d', $step, $step + $stepSize);
mysqli_query($con, $sql);
echo $sql .PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment