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