Sometimes the background requires that a large amount of data is imported into the database, such as the query of the computer test score, the data of the phone book is generally stored in Excel. At this time, we can export the data into a CSV file, then pass the following procedure Data can be imported into the database in the background batch. All programs and database structures are all in the package file, click here to download http://home.nuc.edu.cn/~arcow/display.php?id=109 below is just the main program part: Php / ** ******************************************************** Author : Rushing /ar /arcow***********************NJJ@nuc.edu.cn************ ***************** PHP import CSV file to the database **************************************** ********************************************************* / // Define the acquisition time function function getmicrotime () {list ($ @ec, $ sec) = expLode (", microtime ()); return ((float) $ uec (float) $ sec);}?>
php $ time_start = getMicRotime (); include ("db.inc.php"); // Connect the database $ db = new testcsv;?> php $ handle = fopen ("test.csv", "r" $ SQL = "Idcard, Names, Num, Sex, Nation, Score) Values ('"; while ($ data = fgetcsv ($ Handle, 1000, ")) {$ Num = Count $ DATA); for ($ C = 0; $ C <$ NUM; $ C ) {IF ($ C == $ NUM-1) {$ SQL = $ SQL. $ DATA [$ C]. ') " Break;} $ data [$ C]. "','";} print "
"; Echo $ SQL. "
"; $ db-> query ($ sql) Echo "SQL statement execution is successful!
"; $ SQL = "Insert Into Score (IDCard, Names, Num, SEX, NATION, Score) Values ('";} fclose; $ TIME_END = GetMicrotime ); $ TIME = $ TIME_END - $ TIME_START; Echo "program execution time:" $ TIME. "second";