如何读取文本文件并使用php将这些值插入数据库

时间:2013-12-31 09:26:17

标签: php mysql text

我有一个像这样的文本文件名为ernakulam.txt,其内容如下:

name1
name2
name3
name4
name5

我想将此值插入名为places的Mysql数据库表中。 Mysql表有这样的字段:

dist_id  |  name
_________|______
         |
         |

在此表中,field1(dist_id)对于所有行应该相同。 dist_id值是6.如何从文本文件中读取这些名称并使用php插入Mysql表?

1 个答案:

答案 0 :(得分:2)

<?php

$file = '/path/to/ernakulam.txt';
$file_content = file_get_contents($file);
$names = explode("\n", $file_content);

等等

相关问题