PHP MySQL LOAD DATA INFILE帮助 [英] PHP MySQL LOAD DATA INFILE Help

查看:60
本文介绍了PHP MySQL LOAD DATA INFILE帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法正确地执行此查询.基本上,我从表单中获取一个csv并尝试将其加载到数据库中.我从phpmyadmin获取了大部分查询.我应该使用临时文件,对不对?这是...

I just can't seem to get this query right. Basically I'm taking a csv from a form and trying to load it into the database. I took the majority of the query from phpmyadmin. i should be using the temp file right? here it is...

<form name = "price_chart" method="post" action="index.php?option=<?php echo $option ?>&task=complete" enctype="multipart/form-data">
<label>File: </label>
<input type="file" name="white" id="white"/><br />
<input type="hidden" value="TEST" name = "test" />
<input type="submit" name = "upload" value="Upload File" />
</form>

<?php
}
function complete($option){
$pfile = $_FILES['white']['name'];  
$ptmpName = $_FILES['white']['tmp_name'];
$test = $_POST['test'];
$result = mysql_query("LOAD DATA LOCAL INFILE '$ptmpName' REPLACE INTO TABLE 'jos_rates_table' FIELDS TERMINATED BY ',' ENCLOSED BY ' ' ESCAPED BY '\\' LINES TERMINATED BY '\n'('country' , 'rate')")or die ('Error: '.mysql_error ());
        while ($row = mysql_fetch_array($result)) {
        }
        $num_rows = mysql_num_rows($result);
        echo $num_rows;
}

更新:这是错误消息

您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的"jos_rates_table" FIELDS TERMINATED BY','ENCLOSED BY''ESCAPED BY'\'LINES'附近使用

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''jos_rates_table' FIELDS TERMINATED BY ',' ENCLOSED BY ' ' ESCAPED BY '\' LINES ' at line 1

推荐答案

您需要在行终止子句中使用斜杠,否则,您只需在查询中添加换行符即可.

You need to escape the slash for the lines terminated clause, otherwise you just added a newline to your query.

LINES TERMINATED BY '\\n'

Mysql只会得到\n,但是PHP会尝试解释这些内容,因此您必须对其进行转义.

Mysql will just get \n, but PHP tries to interpret those so you have to escape them.

您可能还有其他问题,但是您没有告诉我们会发生什么情况.

You may have other issues, but you haven't told us what happens.

这篇关于PHP MySQL LOAD DATA INFILE帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆