Convert data from Excel to mysql with 20 rows of statements

Source: Internet
Author: User
After 20 rows of statements are converted from Excel to mysql, I have learned a little about php and mysql, I want to secretly "share" this confidential commercial data, while thinking about how to get it, while thinking about how to convert it into a mysql database, I went to many php site forums to ask experts, there was no result, why don't you try this method one day? The results are also true. everything is OK. I will share my experience with you (maybe you have a better way)
Shard decomposition:
1) select all records in field a and select "Copy"
Bytes
32.16a.xlsa.txt (format: "text files (tab-separated )")
In the 42.16e.xls, the numbers of other 3 fields are 1 to 3, and B .txt, c.txt, and d.txt are continuously generated.
2. after completing the above steps, you have completed most of the work. The following is done by php and mysql, which is simple:
1) to put data in mysql, you must create a mysql database named dbname (consistent with the dbname in php code), including the table tbname (consistent with the tbname in php code ), the four fields inc char (100), adds char (100), pri char (100), and tel char (100) must be adjusted according to the field size in Excel, otherwise, the part score may be lost.
2) writing php code is the most important. the code is as follows:
------ Txt2mysql. php ---------
$ Inc = file ("a.txt ");
$ Adds = file ("B .txt ");
$ Pri = file ("c.txt ");
$ Tel = file ("d.txt ");
$ I = 0;
Mysql_connect ();
While (strlen ($ inc [$ I])> 0)
{
$ SQL = "insert into tbname values ('$ inc [$ I]', '$ adds [$ I]', '$ pri [$ I]', '$ tel [$ I]') ";
$ Do = mysql_db_query ("dbname", $ SQL );
$ I = $ I + 1;
Echo'
';
}
$ S = "select * from tbname ";
$ Gg = mysql_db_query ("dbname", $ s );
$ N = mysql_num_rows ($ gg );
Mysql_close ();
Echo'
';
Echo "added". $ n. "records ";
?>

Note: a.txt, B .txt,c.txt,d.txt and txt2mysql. php must be in the same directory.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.