Using txt file insert bulk data in mysql database


Upload csv file using form and read data line by line and insert in mysql-database.

$handleFo = fopen($_FILES[‘firstExcel’][‘tmp_name’], “r”);// upload by form

$handleFo = ‘unique_markets.txt’;// direct access

if (($handle = fopen($url, “r”)) !== FALSE) // direct access (fopen and fclose not require when using form method)
{

while(! feof($fileticket))
{

$exp = explode(‘||’, fgets($fileticket));
$imports[] = “(‘”.addslashes($exp[0]).”‘,'”.addslashes($exp[1]).”‘)”;
}

$importarrays = array_chunk($imports, 10000);
foreach($importarrays as $arr) {

mysql_query(“INSERT INTO unique_markets_new (Origin, Destination) VALUES “.implode(‘,’, $arr));

}

fclose($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