Php 将数据从数据库放入文本文件

Php 将数据从数据库放入文本文件,php,mysqli,Php,Mysqli,我有一个文本文件,其中包含例如: The Fulton County Grand Jury said Friday an investigation. The jury further said in term-end presentments that the City Executive Committee. etc.. ========================== = id = word = type = ========================== = 1

我有一个文本文件,其中包含例如:

The Fulton County Grand Jury said Friday an investigation.
The jury further said in term-end presentments that the City Executive Committee.
etc..
==========================
= id =    word  =  type  =
==========================
= 1  =  country = nn-tl  =
= etc...                 =
==========================
我在数据库中有一个单词词典表,例如:

The Fulton County Grand Jury said Friday an investigation.
The jury further said in term-end presentments that the City Executive Committee.
etc..
==========================
= id =    word  =  type  =
==========================
= 1  =  country = nn-tl  =
= etc...                 =
==========================
我必须使用数据库中字典上的单词搜索文本文件中的相同单词,并获取相同单词的类型,然后使用格式
words/type
将它们添加到文本文件中,因此最终结果必须是:

The/at Fulton/np-tl County/nn-tl Grand/jj-tl Jury/nn-tl said/vbd Friday/nr an/at investigation/nn ./.
etc..
代码如下: connection.php

$db = new mysqli("localhost","root","root","peri");
if(mysqli_connect_errno()){
   trigger_error('Connection failed: '.$db->error);
}
主要节目:

require_once 'connection.php';
$file  = "C:/AppServ/www/dictionary/text.txt";
$lines = file($file);
foreach($lines as $line_num => $line) {
     $parse = explode(' ', $line);  
     $query = $db->query("SELECT typeword FROM dictionary WHERE words = $parse");
     $result = $query->fetch_object();
      echo $parse '/' $result";
}
但它给我错误消息
调用非对象上的成员函数fetch_object()

请帮助我,谢谢:)

假设您有一个包含字段的字典表:id、word、type和示例文本文件,这可能是一个解决方案(可能您需要在这里和那里进行一些调整!):


请注意,您可能必须替换:,!?。。。要匹配数据库中的单词…

请尝试
(“从字典中选择typeword,其中单词=”“$parse。””)
您在
echo$parse'/“$result”中有一个语法";$parse是数组,它会工作吗?@nevermind不,它不会工作。如何让它工作?@user3714179,文本文件中的每个单词都在“dictionary”表中,它有它的类型吗?如果未找到-应打印什么?另外,词典中的单词是否完全相同,例如“The”-大写?