我似乎无法正确地编写此查询。基本上,我正在从表单中获取一个csv文件,并尝试将其加载到数据库中。我从phpmyadmin中取了大部分查询。我应该使用临时文件,对吗?以下是查询:
<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。