使用PHP将简单的excel数据导出到MySQL中 [英] Export simple excel data into MySQL using PHP

查看:186
本文介绍了使用PHP将简单的excel数据导出到MySQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户端具有以下结构的excel文件

My client got a excel file with the following structure

name     |     email
----------------------------
Name     |   email here
Name     |   email here
Name     |   email here
Name     |   email here
Name     |   email here
Name     |   email here

我想根据这种模式创建一个MySQL数据库表,并将数据保存到MySQL

I would likes to make a MySQL database table according to this pattern and save the data into MySQL.

我很想知道如何做到这一点。
还有一个选项需要

I am wonder how to do this. Also there is an option needed

我们必须检查,如果相应的用户有一个正确的电子邮件地址,即表单@。

We have to check that if that corresponding user had a correct email address, ie of the form @ .

我们可以在导入时检查数据为循环吗?

Can we check the data as a loop while importing ?

还有如何将此数据转换为MySQL?

Also how to convert this data to MySQL ?

推荐答案

将此excel文件另存为csv并运行以下代码添加更改

Save this excel file as csv and run the following code with add your changings

$source = fopen('email.csv', 'r') or die("Problem open file");
    while (($data = fgetcsv($source, 1000, ",")) !== FALSE)
    {
        $name = $data[0];
        $email = $data[1];


        mysql_query("INSERT INTO `table` (`name`,`email`) VALUES ('".$name."','".$email."') ");


    }
    fclose($source);

这篇关于使用PHP将简单的excel数据导出到MySQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆