Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upload Excel files and import data to MySQL database by PHP

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "PHP how to upload Excel files to import data into the MySQL database", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let the editor lead you to study and learn "PHP how to upload Excel files to import data to the MySQL database" this article.

Recently, I have been doing Excel files to import data into the database. If the website wants to support bulk insertion of data, it can create an upload Excel file and import the data contents into Mini Program of MySQL database.

Tools to be used:

ThinkPHP: lightweight domestic PHP development framework. It can be downloaded from ThinkPHP's official website.

A PHP class library for PHPExcel:Office Excel documents, based on Microsoft's OpenXML standard and PHP language. It can be downloaded from CodePlex's official website. 、

1. Design MySQL database product

Create a product database

CREATE DATABASE product DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

Create pro_info table, table structure

CREATE TABLE pro_info (pId int (4) NOT NULL PRIMARY KEY AUTO_INCREMENT,pName varchar (20) NOT NULL,pPrice float NOT NULL,pCount float NOT NULL)

two。 Build a project

First, create a new index.php file under the same level directory of ThinkPHP, and generate the project Home.

3. Upload file form

Create a new Index folder under the Home/Tpl folder, and create a new index.html file in it.

Upload Files:

4. Write the method to display the upload form page, upload Excel file and import Excel file in / Home/Lib/Action/IndexAction.class.php (if there is no expansion package under ThinkPHP/Extend, you need to download it on the ThinkPHP official website, and then decompress the expansion package and put it into it)

5. test

The above is all the contents of the article "how to upload Excel files and import data into MySQL database by PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report