Using CSV 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.csv’; //direct access

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

while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE)
$imports[] = “(‘”.addslashes($data[0]).”‘,'”.addslashes($data[1]).”‘)”;

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

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





Leave a Reply

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

You are commenting using your 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