Split large SQL file into small files using PHP code


Please find below code to Split large SQL file into small files

$file_handle = fopen(‘sql/file.sql’,’r’); //open big file with fopen
$f = 1; //new file number
while(!feof($file_handle))
{
$newfile = fopen(‘sql/splitfile-‘ . $f . ‘.sql’,’w’); //create new file to write to with file number
for($i = 1; $i <= 3000; $i++) //for 3000 lines
{
$import = fgets($file_handle);
fwrite($newfile,$import);
if(feof($file_handle))
{break;} //If file ends, break loop
}
fclose($newfile);
//MySQL newfile insertion stuff goes here
$f++;
}
fclose($file_handle);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s