Home > Article > Backend Development > The fgetcsv function in php imports csv files into mysql database_PHP tutorial
This article will give you a detailed introduction to the fgetcsv function to import csv files into the mysql database. At the same time, the solution to Chinese garbled characters can be referred to.
When processing large batches of excel data to the mysql database, use the fgetcsv function that comes with PHP to first obtain the data line by line from the csv file, and then import it into the database with the sql statement. If you encounter garbled characters, you can use the iconv function to transcode.
Code example:
The code is as follows
|
Copy code
$handle = fopen("test.csv","r");
$num = count($data); Row $row has $num fields. setlocale(LC_ALL, 'zh_CN.UTF8′);
for ($c=0; $c < $num; $c++) { |