Created
December 4, 2012 07:49
-
-
Save fredrike/4201640 to your computer and use it in GitHub Desktop.
Split huge array of rows to smaller chuncks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The idea is to test against the value $max_allowed_packet (in bytes) | |
* and make sure our sql don't get bigger than that. | |
* Before executing our query (the bigger INSERT the less overhead. | |
*/ | |
// $rows is an array containing the rows to insert | |
while(count($rows)) { | |
$sql = "INSERT IGNORE INTO `table` VALUES ". | |
implode(',',array_splice($rows,0,25000)). | |
";".PHP_EOL; | |
if(!$db->query($sql)) | |
die($db->error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps something like this: http://stackoverflow.com/a/7942680/803002