文件无法通过PHP上传到MySQL

时间:2015-03-02 04:06:33

标签: php mysql laravel

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

    $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);

它在Localhost中完美运行。当我在服务器中尝试它时,发生以下错误:

{"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}}

我在local-infile=1文件中更改了my.cnf的值。仍然,得到相同的错误。

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

你可能必须在my.cnf文件和php PDO中启用它。

[mysqld]
local-infile 

[mysql]
local-infile 

和......

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