Import csv file data into mysql database using php

Import csv file data into mysql database using php

In this Post We Will Explain About is Import csv file data into mysql database 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 import csv file into mysql using php codeExample

In this post we will show you Best way to implement import csv file into mysql using php demo, hear for how to read csv file in php and store in mysqlwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :  how to call helper function in codeigniter view

Example

here show eamples to core PHP with mysql we can easily read the simple CSV file data into database like as a mysql database. CSV (comma separator value) file contain the all data with simple separator comma. functions used to fgetcsv is used to read simple csv data.

index.php

<?php  
$db_connect = mysql_connect("127.0.0.1","root",""); 
mysql_select_db("livecsv",$db_connect);


if (isset($_FILES['livecsv']['size']) > 0) { 
    $file = $_FILES['livecsv']['tmp_name']; 
    $handle = fopen($file,"r"); 
    $name = $_FILES['livecsv']['name'];
    do { 
        if ($data[0]) { 
		$myquery = mysql_num_rows(mysql_query("SELECT user_id FROM user_mst WHERE user_id = '".addslashes(trim($data[1],'"'))."'"));
		if($myquery == 0 ) {
            mysql_query("INSERT INTO user_mst (user_name, user_id,user_file) VALUES 
                ( 
                    '".addslashes(trim($data[0],'"'))."', 
                    '".addslashes(trim($data[1],'"'))."',
					'".$name."'
                ) 
            "); 
		}
        } 
    } while ($data = fgetcsv($handle,1000,",","'"));     // 

	echo '<script> window.loaction.href="../index.php?responseid=1" </script>';
     die; 

} 

?> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Devloped By : Pakainfo.com Import a CSV File with PHP & MySQL</title> 
</head> 
<body> 
<?php if (isset($_GET['success'])) { echo "<b>Your simple file has been imported success.</b><br><br>"; } //generic simple success notice ?> 
<h1>Devloped By : Pakainfo.com - Import a CSV File with PHP AND MySQL Example</h1>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
  select your file: <br /> 
  <input name="livecsv" type="file" id="livecsv" /> 
  <input type="submit" name="Submit" value="Submit" /> 
</form> 

<p>We are Web Technology Experts and Team who provide you very Important information on Web Development information,Examples and Demo, Interview Questions and Answers, live project problem solution and their solution and online free tutorials – “Pakainfo.com”.

1) https://pakainfo.com/

2) https://pakainfo.com/tutorial</p>
</body> 
</html>

Your CSV simple data must be like below : CSV File Sample Data

919898225076, ravi
919974840402, live24udotcom
919898555554, itfiddledotcom
919985666854, MayurDhameliya

Example

I hope you have Got What is import csv file into mysql database using phpmyadmin 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.

Recommended For You.

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

Add a Comment

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