To import an excel file from php to the mysql database, we need to use a phpexcel file. with this file, we can quickly and easily import an excel file to the mysql database, the following is an example for you... to import an excel file from php to the mysql database, we need to use a phpexcel file. with this file, we can quickly and easily import an excel file to the mysql database, the following is an example to help you.
Prepare a database before import. the SQL statement code is as follows:
/* Navicat MySQL Data Transfer Source Server : www.phprm.com localhost Source Server Version : 50133 Source Host : localhost:3306 Source Database : test Target Server Type : MYSQL Target Server Version : 50133 File Encoding : 65001 Date: 2011-10-11 14:11:38 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `execl` -- ---------------------------- DROP TABLE IF EXISTS `execl`; CREATE TABLE `execl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=latin1; -- ---------------------------- -- Records of execl -- ---------------------------- INSERT INTO `execl` VALUES ('14', 'jim'); INSERT INTO `execl` VALUES ('15', 'taurus');
Php processing program. here we need to use a phpexcel file, which can be searched and downloaded by Baidu. the code is as follows:
SetOutputEncoding ('cp936'); $ data-> read ($ _ FILES ['execl'] ['name']); error_reporting (E_ALL ^ E_NOTICE ); $ SQL = ""; for ($ I = 1; $ I <= $ data-> sheets [0] ['numrows ']; $ I ++) {// open source code phprm.com if ($ data-> sheets [0] ['cells '] [$ I] [1]! = "") {$ SQL = "INSERT INTO 'execl' ('name') values ('". $ data-> sheets [0] ['cells '] [$ I] [2]. "');"; if (mysql_query ($ SQL) {echo 'successfully';} else {die ('failed ');}}}}
Link to this article:
Add to favorites ^ please keep the tutorial address.