The examples in this article describe the import and export classes of PHP implementation CSV files. Share to everyone for your reference. as follows:
I hope this article will help you with your PHP programming.
The following are just the main program sections:
The code is as follows
Copy Code
/*****************************************Author: Chong Xing/arcow****************njj@nuc.edu.cn*******************PHP import CSV file to database **********Simultaneous calculation of program execution time ***********www.111cn.net***************************************************/Define Get Tim
Php imports the csv file to the mysql database. Php imports a csv file to the mysql database * the principle of data import in this program is to first upload the csv file to the server, and then save the data to the array through
MySQL has a CSV engine that can be used to import data from CSV into a MySQL database faster than a batch program written in PHP or Python.
Examples of specific implementation code:
Copy CodeThe code is as follows:
Load data infile '/tmp/file.csv ' into table _tablename (se
, lineSupedSeped"End');
Select * from test_info;
Select * from test_info into outfile '/tmp/test.csv' fields terminated by ', 'optionally enclosed by' "'escaped by '" 'lines terminated by'/r/N ';
Delete from test_info;
Load data infile '/tmp/test.csv' into table test_info fields terminated by ', 'optionally enclosed by' "'fig by '" 'lines terminated by'/r/N ';
Select * from test_info;
File: test.csv
Text Code2010, "hello, lineSupedSeped""End"
2010, "hello, lineSupedSeped""End"
In Linux, if you
following script, the user, pass, socket and other variables for mysql data connection are connections in my test environment. you can modify the variables as needed when using the script;In addition, you can modify the database name, table name, and column name in the script for different csv format and number of rows to solve this problem.
Script 1: The script for creating a database and a data table is
"End');
Select * from test_info;
Select * from test_info into outfile '/tmp/test.csv' fields terminated by ', 'optionally enclosed by' "'escaped by '" 'Lines terminated by' \ r \ n ';
Delete from test_info;
Load data infile '/tmp/test.csv' into table test_info fields terminated by ', 'optionally enclosed by' "'fig by '" 'Lines terminated by' \ r \ n ';
Select * from test_info;
File: test.csv
Text code2010, "hello, lineSupedSeped""End"
2010, "hello, lineSupedSeped""End"
In Linux, if you need to
In php, the fgetcsv function imports the csv file into the mysql database. This article will introduce the fgetcsv function to the specific functions of the mysql database for importing csv files. you can also find a solution to Chinese garbled characters. This article describes how to
MySQL tutorial export XLS and CSV data implementation and garbled solutionFollowing aboutFirst look at MySQL Export import xls and CSV data instance methods, while encountering the import of garbled when the effective solution,
E
Tags: csvExport MySQL data into CSV format for fast import and export, both locally and remotelyMySQL comes with data export commands (local export)Export: SELECT * from TableA to outfile '/tmp/aa.csv ' fields terminated by ', ' optionally enclosed by ' "' lines terminated by ' \ n ' "Import: Load Data infile "/tmp/fil
PHP to import the CSV file into the MySQL database method,
This example describes how PHP imports a CSV file into a MySQL database. Share to everyone for your reference. The specific analysis is as follows:
This program to implement data
MySQL itself has a CSV engine that allows you to import data from a CSV into a MySQL database, faster than a batch program written in PHP or Python.specific implementation code examples:
Copy Code code as follows:
Load data infile '/tmp/file.csv ' into table _tablename (set
MySQL itself has a CSV engine that allows you to import data from a CSV into a MySQL database, faster than a batch program written in PHP or Python.
specific implementation code examples:
Copy Code code as follows:
Load data infile '/tmp/file.csv ' into table
What if I need to analyze the access log now?Like analyzing D:\Servers\Apache2.2\logs\access2014-05-22.log .http://my.oschina.net/cart/ developed a gadget to analyze Apache logs, split the word interleaved CSV file and insert MySQL database analysis for this issuePHP$date= ' 2014-05-22 ';file_put_contents($date.‘. CSV ', ' ');file_put_contents($date.‘.
You can use load data infile to import a *. csv file to mysql,
Summary:
Load data [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.csv'
[REPLACE | IGNORE]
Into table tbl_name
[FIELDS
[Terminated by 'string']
[[OPTIONALLY] enclosed by 'Char ']
[Escaped by 'Char ']
]
[LINES
[Starting by 'string']
[Terminated by 'string']
]
[IGNORE number LINES]
[(Col_name_or_u
You can use load data infile to import a *. csv file to mysql,
Summary:
Load data in file
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Load data [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.csv'[REPLACE | IGNORE]Into table tbl_name[FIELDS[Terminated by 'string'][[OPTIONALLY] enclosed by 'Char '][Escap
This article will introduce the fgetcsv function to the specific functions of the mysql database for importing csv files. You can also find a solution to Chinese garbled characters.
When processing a large volume of excel Data to the mysql database, use the fgetcsv function provided by php to first obtain data from the csv
Php uses the specified encoding to export mysql data to a csv file. Php uses the specified encoding to export mysql data to csv files. This document describes how php exports mysql data to csv files using the specified encoding. S
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.