Convert data from Excel to MySQL with 20 rows of statements

Source: Internet
Author: User

Since I had some knowledge of PHP and MySQL, I have been very keen on my company's huge Excel database and want to secretly "share" the confidential commercial data, while thinking about how to get it, thinking about how to convert it into a MySQL database, and going to many PHP site forums to consult experts, there is no result, one day suddenly imagine, why not try this method? 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 store data in MySQL, you must create a MySQL database named dbname ( Code Dbname must be consistent), including the table tbname (must be consistent with the tbname in PHP code), four fields Inc char (100), adds char (100), PRI char (100 ), tel char (100), the size should 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 '<br> ';
}
$ S = "select * From tbname ";
$ Gg = mysql_db_query ("dbname", $ S );
$ N = mysql_num_rows ($ GG );
Mysql_close ();
Echo '<br> ';
Echo "added". $ n. "records ";
?>

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

Related Article

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.