? Connect to the database file $ connectmysql_connect (localhost, admin, admin) ordie (link to the database failed !); Waiting for ($ i0;
? // Connect to the database file $ connect = mysql_connect ("localhost", "admin", "admin") or die ("failed to connect to the database! "); // Connect to the database (test) mysql_select_db (" testcg ", $ connect) or die (mysql_error (); $ temp = file (" test.csv "); // connect the excelfile in the format of .csv for ($ I = 0;
// Connect to the database file
$ Connect = mysql_connect ("localhost", "admin", "admin") or die ("failed to connect to the database! ");
// Connect to the database (test)
Mysql_select_db ("testcg", $ connect) or die (mysql_error ());
$ Temp = file ("test.csv"); // connect to the excelfile, in the format of .csv
For ($ I = 0; $ I {
$ String = explode (",", $ temp [$ I]); // obtain the value of each record in an EXCEL file in a loop
// Insert the values of each record in the EXCEL file into the database
$ Q = "insert into ceshi (name, num, dom) values ('$ string [0]', '$ string [1]', '$ string [2]'); ";
Mysql_query ($ q) or die (mysql_error ());
If (! Mysql_error ());
{
Echo "data imported successfully! ";
}
Echo $ string [4]. "\ n ";
Unset ($ string );
}
?>
--------------------------------------------------------------------------------
Phpexcel or pear is a component with an Excel class plug-in China.
All of them are used to process excel. The first two functions are quite powerful and support for encoding is also good. We recommend that you use pear, which is called spreadsheet reader.
Phpexcel is charged for resources, but not all excel files can be read.
You can go to pear.php.net
--------------------------------------------------------------------------------
Answer on the top floor ~~ By the way, the answer is! Hey
--------------------------------------------------------------------------------
AdO direct upload
Note that some characters may not be supported by mysql or ADO
--------------------------------------------------------------------------------
First, confirm the encoding of your database. Take UTF-8 as an example,
Open the excel file, save it, and select ". CSV" as the file.
Then open the. csv file with the compiler and save it as a UTF-8 csv file.
Then, you can use php's getcsv to open the php file (this ensures that some of your fields are included, resulting in parsing errors), and then import the parsed results to the database.
Then it's done.