Showing posts with label xpress upload. Show all posts
Showing posts with label xpress upload. Show all posts

Friday, 28 August 2015

How to upload large amount of data within seconds into mysql database USING csv file



Using this php script you can upload thousands of  record  within a second

1. HTML form for upload csv file -

<form name="import" method="post" enctype="multipart/form-data">
        <input type="file" name="file" /><br />
        <input type="submit" name="submit" value="Submit" />
    </form>




2. PHP Script FOr Execution -
<?php
    $con = mysql_connect('localhost','root','123456'); //database Connections
if(!$con){die(mysql_error());
}
else
{
mysql_select_db('test',$con);
}

   
    if(isset($_POST["submit"]))
    {
$status=2;       
  move_uploaded_file($_FILES["file"]["tmp_name"],
      "/var/www/html/importviaexcel/upload/" . $_FILES["file"]["name"]);
      $file_path="/var/www/html/importviaexcel/upload/" . $_FILES["file"]["name"]; //file & folder name Where csv uploaded

echo "My file - ".$file_path;
$table="csv";
$fp = file("$file_path");
$total_count=count($fp);
echo "Total record - ".count($fp);
$sql_load =     " LOAD DATA INFILE '".$file_path."'" . 
            "IGNORE INTO TABLE " . $table . 
            " FIELDS TERMINATED BY " . "','" . 
            // " LINES TERMINTED BY " . "\r\n" . 
            " IGNORE 1 LINES
            ( @no,@name,@mobile,@email)
            set
            no = @no,
            name = @name,
            mobile = @mobile,
            email = @email,
            status = '2' 
            ";


$result = mysql_query($sql_load, $con);

$upload_rec=mysql_affected_rows();
$duplicate=$total_count-$upload_rec;
echo "Total - $total_count </br>Upload - $upload_rec </br> duplicate - $duplicate  ";
           

    }
?>




  Hope it will Helpful for you.