gpt4 book ai didi

php - 加载数据本地infile mysql服务器php Ubuntu

转载 作者:行者123 更新时间:2023-11-29 22:43:41 26 4
gpt4 key购买 nike

我发布了该解决方案,因为它让我发疯了几天——结果是 AppArmor 设置。这个线程终于让我解决了: How can I get around MySQL Errcode 13 with SELECT INTO OUTFILE?

我看到这被标记为重复,但所有其他建议似乎都指向编辑 my.cnf,这对我不起作用。

我无法让 Load Data Local Infile 正常工作。我的MySQL服务器版本是5.5.41,我的Ubuntu版本是14.04.2。我的my.cnf在mysql、mysqld和client下都有“local-infile”。我在下面根据 Stackoverflow 上的另一篇文章在连接字符串中指定了标志 128。当我在客户端上运行下面的代码时效果很好,但现在它位于服务器上,它不断抛出

"The used command is not allowed with this MySQL version.

编辑,从命令行运行此命令成功:

mysql> LOAD DATA LOCAL INFILE '/home/aa/ER.csv'
-> INTO TABLE ER_import
-> FIELDS TERMINATED BY ','
-> LINES TERMINATED BY '\r\n'
-> IGNORE 1 LINES
-> (Paid_Amount,
-> Pro_Number,
-> Invoice,
-> Ship_Date,
-> BL,
-> Carrier_Name,
-> Check_Number,
-> Paid_Date,
-> Shipper_City,
-> Shipper_State,
-> Shipper_Name_1,
-> Recipient_City,
-> Recipient_State,
-> Recipient_Name_1,
-> Batch_Number,
-> Actual_Weight,
-> Billed_Amount
-> );
Query OK, 8585 rows affected, 4 warnings (0.21 sec)
Records: 8585 Deleted: 0 Skipped: 0 Warnings: 4

然而,这不断重新调整找不到文件:“文件'/home/aa/ER.csv'未找到(错误代码:13)”文件肯定存在并且权限正确:

$delete = "DELETE FROM ER_import";

if (!mysqli_query($conn,$delete))
{
echo("Error description: " . mysqli_error($conn));
}

$query = <<<eof
LOAD DATA INFILE '/home/aa/ER.csv'
INTO TABLE ER_import
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(Paid_Amount,
Pro_Number,
Invoice,
Ship_Date,
BL,
Carrier_Name,
Check_Number,
Paid_Date,
Shipper_City,
Shipper_State,
Shipper_Name_1,
Recipient_City,
Recipient_State,
Recipient_Name_1,
Batch_Number,
Actual_Weight,
Billed_Amount
);
eof;


if($results = mysqli_query($conn, $query)){
echo $file. " has been imported!";
} else die(mysqli_error($conn));

这是显而易见的事情吗?

最佳答案

试试这个方法

$query = <<<eof
LOAD DATA LOCAL INFILE DIR_FILE
INTO TABLE ER_import
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
eof;

$query = str_replace('DIR_FILE',$dir.$file,$query);

因为<<<eof意味着您不希望 php 解析以下字符串中的任何内容。但你正在尝试$dir$file这意味着您期望 php 会用值替换此变量。

关于php - 加载数据本地infile mysql服务器php Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29220132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com