【问题标题】:How to copy data from a .txt file to a .sql file or in a database table using PHP [duplicate]如何使用 PHP 将数据从 .txt 文件复制到 .sql 文件或数据库表中 [重复]
【发布时间】:2013-02-04 07:36:08
【问题描述】:

可能重复:
Import large csv file to mysql database using php

1. 我的 public_html 文件夹中有一个名为 un.txt 的 .txt 文件,其中包含 4000 个用户名,如下所示:

用户名1,用户名2,用户名3,.....

2. 我在数据库 members 中创建了一个名为 oldusernames 的表。该表只有一列名为 oldusers。我正在使用 MySql。

如何将文件 un.txt 中的所有用户名导入 oldusers 中的我的数据库(members)表(oldusernames字段使用PHP

【问题讨论】:

标签: php mysql import


【解决方案1】:

步骤(请记住,我们不应该为您编写大量代码):

  1. 在 PHP 中加载文本文件 (look at PHP's file functions)
  2. 将字符串拆分为数组元素,以逗号分隔 (look at PHP's explode function)
  3. 循环遍历每个数组元素并将其插入数据库。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 2014-01-02
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多