php导入excel文件到mysql数据库的方法,
本文实例讲述了php导入excel文件到mysql数据库的方法。分享给大家供大家参考。具体分析如下:
php导入excel文件入mysql数据库我们是需一借助一个phpexcel类文件了,有了这个类文件我们就可以快速简单的导入excel到mysql数据库中,这里就来举个例子给大家说明一下具体用法.
导入前我们需要先准备一个数据库,sql语句代码如下:
复制代码 代码如下:
/*
Navicat MySQL Data Transfer
Source Server : 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处理程序,在这里我们需要使用一个phpexcel类文件了,这个可以百度搜索下载,代码如下:
复制代码 代码如下:
if($_FILES['execl']['name']){
$db = mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query('set names gbk');
require_once 'reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP936');
$data->read($_FILES['execl']['name']);
error_reporting(E_ALL ^ E_NOTICE);
$sql = "";
for($i=1;$isheets[0]['numRows'];$i++)
{
if($data->sheets[0]['cells'][$i][1]!=""){
$sql = "INSERT INTO `execl`(`name`)values('".$data->sheets[0]['cells'][$i][2]."');";
if(mysql_query($sql)){
echo '成功';
}else{
die('失败');
}
}
}
}
?>
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor