Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php读取文本文件并将这些值插入数据库_Php_Mysql_Text - Fatal编程技术网

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

如何使用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 _________|______ | |

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

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);