php導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法
Jun 13, 2016 am 09:10 AMphp導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法
?這篇文章主要介紹了php導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法,分析了phpexcel類操作excel文件的技巧及導(dǎo)入數(shù)據(jù)庫的方法,具有一定參考借鑒價值,需要的朋友可以參考下
?
?
本文實例講述了php導(dǎo)入excel文件到mysql數(shù)據(jù)庫的方法。分享給大家供大家參考。具體分析如下:
php導(dǎo)入excel文件入mysql數(shù)據(jù)庫我們是需一借助一個phpexcel類文件了,有了這個類文件我們就可以快速簡單的導(dǎo)入excel到mysql數(shù)據(jù)庫中,這里就來舉個例子給大家說明一下具體用法.
導(dǎo)入前我們需要先準備一個數(shù)據(jù)庫,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程序設(shè)計有所幫助。

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Avoid N 1 query problems, reduce the number of database queries by loading associated data in advance; 2. Select only the required fields to avoid loading complete entities to save memory and bandwidth; 3. Use cache strategies reasonably, such as Doctrine's secondary cache or Redis cache high-frequency query results; 4. Optimize the entity life cycle and call clear() regularly to free up memory to prevent memory overflow; 5. Ensure that the database index exists and analyze the generated SQL statements to avoid inefficient queries; 6. Disable automatic change tracking in scenarios where changes are not required, and use arrays or lightweight modes to improve performance. Correct use of ORM requires combining SQL monitoring, caching, batch processing and appropriate optimization to ensure application performance while maintaining development efficiency.

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

ReadonlypropertiesinPHP8.2canonlybeassignedonceintheconstructororatdeclarationandcannotbemodifiedafterward,enforcingimmutabilityatthelanguagelevel.2.Toachievedeepimmutability,wrapmutabletypeslikearraysinArrayObjectorusecustomimmutablecollectionssucha

First, use JavaScript to obtain the user system preferences and locally stored theme settings, and initialize the page theme; 1. The HTML structure contains a button to trigger topic switching; 2. CSS uses: root to define bright theme variables, .dark-mode class defines dark theme variables, and applies these variables through var(); 3. JavaScript detects prefers-color-scheme and reads localStorage to determine the initial theme; 4. Switch the dark-mode class on the html element when clicking the button, and saves the current state to localStorage; 5. All color changes are accompanied by 0.3 seconds transition animation to enhance the user

Use performance analysis tools to locate bottlenecks, use VisualVM or JProfiler in the development and testing stage, and give priority to Async-Profiler in the production environment; 2. Reduce object creation, reuse objects, use StringBuilder to replace string splicing, and select appropriate GC strategies; 3. Optimize collection usage, select and preset initial capacity according to the scene; 4. Optimize concurrency, use concurrent collections, reduce lock granularity, and set thread pool reasonably; 5. Tune JVM parameters, set reasonable heap size and low-latency garbage collector and enable GC logs; 6. Avoid reflection at the code level, replace wrapper classes with basic types, delay initialization, and use final and static; 7. Continuous performance testing and monitoring, combined with JMH

UseGuzzleforrobustHTTPrequestswithheadersandtimeouts.2.ParseHTMLefficientlywithSymfonyDomCrawlerusingCSSselectors.3.HandleJavaScript-heavysitesbyintegratingPuppeteerviaPHPexec()torenderpages.4.Respectrobots.txt,adddelays,rotateuseragents,anduseproxie

TosecureMySQLeffectively,useobject-levelprivilegestolimituseraccessbasedontheirspecificneeds.Beginbyunderstandingthatobject-levelprivilegesapplytodatabases,tables,orcolumns,offeringfinercontrolthanglobalprivileges.Next,applytheprincipleofleastprivile

table-layout:fixed will force the table column width to be determined by the cell width of the first row to avoid the content affecting the layout. 1. Set table-layout:fixed and specify the table width; 2. Set the specific column width ratio for the first row th/td; 3. Use white-space:nowrap, overflow:hidden and text-overflow:ellipsis to control text overflow; 4. Applicable to background management, data reports and other scenarios that require stable layout and high-performance rendering, which can effectively prevent layout jitter and improve rendering efficiency.
