Posted inProgramming / Mysql / Mysqli / php

How To Import CSV File into MySQL using PHP

How To Import CSV File into MySQL using PHP

In this Post We Will Explain About is How To Import CSV File into MySQL using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to Import and Export CSV Files Using PHP and MySQL Example

In this post we will show you Best way to implement How to Import CSV File Data into MySQL Database using PHP, , hear for How To Import CSV File Into MySQL Using PHP with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

How to import CSV in PHP MySQL Example

fgetcsv() PHP method is used to All the read data from some CSV file. First of all make an any excel sheet and root path to save it as .csv format
Here We can download CSV File Demo.
Example to some data import CSV file and MySQL save to database.

index.html


 
File name to import :

submit.php

if(isset($_POST['data_submit'])) {
		$Live_data=$_FILES['filename'];
		if(!$Live_data['size'])
		$err="please any select the file";
		elseif(is_uploaded_file($_FILES['filename']['tmp_name'])){
		$handle = fopen($_FILES['filename']['tmp_name'], "r");
		$live_csvformat="Name,Email,Address,Hobby,Country,Mobile,Course\n";
		$hasNext=1;
		$i=date('Ymdhis',time());
		$fileName="error".$i.".csv";
		$fh=fopen($fileName,"a+");
		while (($Live_data = fgetcsv($handle, 1000, ",")) !== FALSE) {
		IF($Live_data[0]==""||$Live_data[1]==""||$Live_data[2]==""||$Live_data[3]==""||$Live_data[4]==""||$Live_data[5]==""||$Live_data[6]==""){
		$live_csvformat.=$Live_data[0].",".$Live_data[1].",".$Live_data[2].",".$Live_data[3].",".$Live_data[4].",".$Live_data[5].",".$Live_data[6]."\n";
		 
		}
		else{
		if($hasNext) 
		{
			$import="INSERT into infomation
			(name,email,address,hobby,country,mobile,course) values('$Live_data[0]','$Live_data[1]','$Live_data[2]','$Live_data[3]','$Live_data[4]','$Live_data[5]','$Live_data[6]')";
			mysql_query($import);
		}
			}
	$hasNext++;
	}
	$err="Good Luck..!!1Import Done";
	fwrite($fh,$live_csvformat);
	fclose($fh);
	}
}

Example

I hope you have Got What is How to Import CSV File Data Into Mysql Using PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype