gpt4 book ai didi

php - 文件无法通过 PHP 上传到 MySQL

转载 作者:行者123 更新时间:2023-11-29 22:53:38 25 4
gpt4 key购买 nike

我在执行以下查询时遇到问题:

    $csv = $path . $filename;
$query = sprintf("LOAD DATA local INFILE '%s' INTO TABLE users FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES (`firstname`, `lastname`, `username`, `gender`, `email`, `country`, `ethnicity`, `education` )", addslashes($csv));
return DB::connection()->getpdo()->exec($query);

它在本地主机中完美运行。当我在我的服务器上尝试时,出现以下错误:

{"error":{"type":"PDOException","message":"SQLSTATE[42000]: Syntax error or access violation: 1148 The used command is not allowed with this MySQL version","file":"\/var\/www\/vhosts\/xxxxxxxx.com\/httpdocs\/xxxxxxxx.com\/app\/controllers\/UsersController.php","line":224}}

我更改了 my.cnf 文件中 local-infile=1 的值。尽管如此,还是遇到了同样的错误。

可能是什么问题?

最佳答案

您可能必须在 my.cnf 文件和 php PDO 中启用此功能。

[mysqld]
local-infile

[mysql]
local-infile

还有...

<?php
$pdo = new PDO($dsn, $user, $password,
array(PDO::MYSQL_ATTR_LOCAL_INFILE => true)
);

关于php - 文件无法通过 PHP 上传到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28802563/

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