Php 逐行读取文件并在数据库行中保存一行

Php 逐行读取文件并在数据库行中保存一行,php,Php,我无法理解如何在数据库中保存一行。。。 我有网上的文件,我带他去卷发。该文件如下所示: ID | TYPE | LINK_ONE | LINK_TWO -------------------------------------------------------------------------------------- 1 | REFALIAS | http://*.example.com/data/*/*

我无法理解如何在数据库中保存一行。。。 我有网上的文件,我带他去卷发。该文件如下所示:

ID  |   TYPE        |   LINK_ONE                      |  LINK_TWO
--------------------------------------------------------------------------------------
 1  |  REFALIAS     |  http://*.example.com/data/*/*  | http://example.com/data/?q=$2
 2  |  REFALIAS     |  http://*.example.com/data/*/*  | http://example.com/data/?q=$2
 3  |  REFALIAS     |  http://*.example.com/data/*/*  | http://example.com/data/?q=$2
www.example.com/file.txt

重构http://.example.com/data//*2美元

重构http://.example.com/data//*2美元

重构http://.example.com/data//*2美元

重构http://.example.com/data//*2美元

所有内容从网络我采取卷曲和保存在新的文件在我的网站根目录。。。 现在我对在数据库中保存行感到困惑

我的DB shema看起来像这样:

ID  |   TYPE        |   LINK_ONE                      |  LINK_TWO
--------------------------------------------------------------------------------------
 1  |  REFALIAS     |  http://*.example.com/data/*/*  | http://example.com/data/?q=$2
 2  |  REFALIAS     |  http://*.example.com/data/*/*  | http://example.com/data/?q=$2
 3  |  REFALIAS     |  http://*.example.com/data/*/*  | http://example.com/data/?q=$2
我试试这个:

<?php     
$fp = @fopen('myFile.txt', 'r');
    while(!feof($fp)) {
       $buffer = fwrite($fp, 999);
       list($type, $link_one, $link_two) = explode("\n", $buffer);
       mysql_query('INSERT INTO table ('type', 'link_one','link_two' VALUES("{$type}, {$link_one}, {$link_two}");
    }
?>
尝试以下代码:

<?php     
$fp = @fopen('myFile.txt', 'r');
    while(!feof($fp)) {
       $buffer = fgets($fp);
       if (empty($buffer)) continue;
       list($type, $link_one, $link_two) = explode(" ", $buffer);
       mysql_query('INSERT INTO table (`type`, `link_one`, `link_two`) VALUES(\'' . $type . '\', \'' . $link_one . '\', \'' . $link_two . '\')');
    }
?>


您真的在使用fwrite从文件中读取内容吗?在PHP变量名中,以Dollor($)开头,在您的代码中,您将查询字符串与Dollor一起使用。所以PHP将查询字符串看作变量并给出这个错误。您已经使用PHPINIDISPLAY_error$buffer=fwrite($fp,999)隐藏了此通知;你在循环中使用这段代码是什么意思?@Harry-别隐瞒错误,他们会告诉你你的代码是哪里弄错的我是在脑子里写的,没有检查语法错误提示:未定义的偏移量:2;在线---列表($type,$link\u one,$link\u two)=分解(“\n”,$buffer);好啊我懂了。您的代码不仅有语法错误,而且是错误的。您的文件有另一种格式:REFALIAS spacehttp://.example.com/data// 但您使用\n而不是空格分隔符来分解数据。您还必须使用FGET而不是fread。然后你应该检查提取的字符串是否为空。啊,我知道了,现在我要检查。。ThanksAgain“注意:未定义的偏移量:2”可能您有制表符(“\t”)作为分隔符。你能给我一个你档案的链接吗?我来检查一下分离器。