Excel
Since the PHP and MySQL have a certain understanding of the company's huge Excel database, I want to secretly "share" this confidential business data, while pondering how to get it, while thinking about how to convert to MySQL database, to a lot of PHP site Forum Consult Master, There is no result, one day unexpected imagination, why not try this method? The result is also good, everything OK, below I will be my experience with you completely share (maybe you have a better way)
1. First introduce the structure of this Excel database, and named E.xls, there are 4 fields (40 are also fixed), the field name is A,b,c,d, and then the Jm.xls decomposition:
1) Select All records in field A, choose Copy
2) Create a new Excel database file, paste the copied data into a blank field (usually a), and keep the other fields blank and save as A.xls.
3) Save A.xls as A.txt (formatted as "Text file (Tab delimited)")
4) data for the other 3 fields in E.xls continue to generate B.txt,c.txt and d.txt by 1 to 3 steps.
2. After completing the above steps, you have done most of the work, the following is done by PHP and MySQL, very simple:
1) to put the data in MySQL, you must create a MySQL database file named dbname (consistent with dbname in the PHP code), including table Tbname (consistent with Tbname in PHP code), 4 Fields Inc char (+), adds char (+), pri char (+), tel char (100), size to adjust the size of the field in Excel, you may lose some of the value.
2) then write the 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 "Total added". $n. " A record ";
?>
Note: A.txt,b.txt,c.txt,d.txt and txt2mysql.php to be in the same directory
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.