CSV file or Excel table Import database

Source: Internet
Author: User
Tags import database

How to import a CSV file or Excel table into a database:

Excel data directly into MySQL will need to use the Phpexcel open source class, the details can refer to this article ~

Http://www.cnblogs.com/freespider/p/3284828.html

The methods used in this article are:

Excel--> Csv-->mysql

First save Excel as a CSV file, and then start analyzing the data.

The code is as follows:

1<span style= "FONT-SIZE:18PX;" ><?PHP2 //Import a CSV file into a database3 //You can also save the Excel file as a CSV file before importing it4 include("./conn.php");5 $file= "./stu.csv";6 $stu=fopen($file, ' R ');7  while(!feof($stu)){8        Echo"<pre>";9        $row=fgets($stu);Ten         $rs[] =Explode(‘,‘,$row); One } A   -  foreach($rs  as $value){ -         $sql= "INSERT into Stu (Name,score) VALUES ('".$value[0]. "', '".$value[1]. "')"; the          $MQ=mysql_query($sql); -  } -   if($MQ){ -                 Echo"Insert success!" "; +}</span>

  

For example:



CSV file or Excel table Import database

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.