如何使用php读取文本文件并将这些值插入数据库
我有一个这样的文本文件,名为ernakulam.txt,其内容如下:如何使用php读取文本文件并将这些值插入数据库,php,mysql,text,Php,Mysql,Text,我有一个这样的文本文件,名为ernakulam.txt,其内容如下: name1 name2 name3 name4 name5 dist_id | name _________|______ | | 我想将这个值插入名为places的Mysql数据库表中。Mysql表有如下字段: name1 name2 name3 name4 name5 dist_id | name _________|______ | |
name1
name2
name3
name4
name5
dist_id | name
_________|______
|
|
我想将这个值插入名为places的Mysql数据库表中。Mysql表有如下字段:
name1
name2
name3
name4
name5
dist_id | name
_________|______
|
|
在此表中,所有行的字段1(dist_id)应相同。dist_id值为6。如何从文本文件中读取这些名称并使用php插入Mysql表?
和您的尝试?您已经完成的任何代码请在($dat=fread($res))时尝试while代码>您可以使用,然后使用线在数组上循环,修剪它们并使用
<?php
$file = '/path/to/ernakulam.txt';
$file_content = file_get_contents($file);
$names = explode("\n", $file_content);