PHP import CSV file into MySQL database/* This program implementation of data import principle is to upload the CSV file to the server, and then through the PHP fopen and fgetcsv files to save the data to the array, and then use while to insert data into the MySQL database
PHP tutorial to import a CSV file into the MySQL Tutorial database tutorial
/*
This program to implement data import principle is to upload the CSV file to the server, and then through the PHP fopen and fgetcsv files to save the data to an array, and then use while to insert data into the MySQL database
*/
$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 " 1 seconds to the list page, please wait a moment."
?>
http://www.bkjia.com/PHPjc/630837.html www.bkjia.com true http://www.bkjia.com/PHPjc/630837.html techarticle PHP import csv file into MySQL database/* This program implementation of data import principle is to upload the CSV file to the server, and then through the PHP fopen and fgetcsv file to save the data to the array, ...