Sometimes when writing a program, the background requires a large amount of data to be imported into the database. For example, test scores, phone books, etc. are generally data stored in excel. At this time, we can export excel into a csv file, and then use the following program. Batch import data into the database
Upload cvs and import into the database, the test is successful (some codes are not standardized, such as PHP_SELF, which needs to be rewritten as $_SERVER["PHP_SELF"])
PHP code
The following is the quoted content:
$do = copy($_FILES['MyFile']['tmp_name'],$fname); if ($do)
"; } else { echo ""; } ?> <🎜>error_reporting(0 ); <🎜>//Import files in CSV format<🎜>$connect=mysql_connect("localhost","a0530093319","123456") or die("could not connect to database"); <🎜>mysql_select_db(" a0530093319",$connect) or die (mysql_error()); <🎜>$fname = $_FILES['MyFile']['name']; <🎜>$handle=fopen("$fname","r") ; <🎜>while($data=fgetcsv($handle,10000,",")) <🎜>{ <🎜>$q="insert into test (code,name,date) values ('$data[0] ','$data[1]','$data[2]')"; <🎜>mysql_query($q) or die (mysql_error()); <🎜><🎜>} <🎜>fclose($handle ); <🎜>?> Used php to export the database to excel, the test was completely successful PHP code www.devdao.com
Previous article:Detailed explanation of PHP script and database functions (Part 2)_PHP tutorial
Next article:Friends who are learning PHP: How much do you know about PHP database development_PHP tutorial
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
When adding sublime3 to compile system php, use the PHP toolbox, cmd php -v is useless
From 1970-01-01 08:00:00
0
0
0
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|