Home  >  Article  >  Backend Development  >  php import csv file into mysql database_PHP tutorial

php import csv file into mysql database_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:04:35599browse

php import csv file into mysql database /* The principle of data import in this program is to first upload the csv file to the server, then save the data into an array through php's fopen and fgetcsv files, and then use while to insert the data into the mysql database one by one

php tutorial to convert csv files Import to mysql tutorial database tutorial
/*
The principle of data import in this program is to first upload the csv file to the server, then save the data to the array through php's fopen and fgetcsv files, and then use while to insert the data into the mysql database one by one
*/

$fname = $_files['myfile']['name'];
$do = copy($_files['myfile']['tmp_name'],$fname);
if ($do){
echo "Import data successfully
";
}else{
echo "";
}

error_reporting(0);//Import files in csv format
$connect=mysql_connect("localhost","root","") or die("could not connect to database");
mysql_select_db("gklqtzcx",$connect) or die (mysql_error());
mysql_query("set names 'gbk'");
$fname = $_files['myfile']['name'];
$handle=fopen("$fname","r");
while($data=fgetcsv($handle,10000,",")){
$q="insert into records (name,classes,a_time,college,notify,receiver,r_time,handler) values ​​('$data[1]','$data[2]','$data[3]', '$data[4]','$data[5]','$data[6]','$data[7]','$data[8]')";
mysql_query($q) or die (mysql_error());
}
fclose($handle);
echo "It will transfer to the list page in 1 second, please wait."

?>

" method="post">

Import cvs data


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630837.htmlTechArticlephp Import the csv file into the mysql database/*The principle of data import in this program is to first upload the csv file to the server , and then save the data to the array through php's fopen and fgetcsv files, and then...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn