LOAD DATA LOCAL INFILE 禁止在... PHP [英] LOAD DATA LOCAL INFILE forbidden in... PHP

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

问题描述

我正在尝试使用 LOAD DATA INFILE 将一些记录插入表中.不幸的是,它不起作用.

I am trying to use LOAD DATA INFILE to insert some records into a table. Unfortunately, it's not working.

这里有一些细节

如果我使用这个指令:

LOAD DATA INFILE 'file.txt'
INTO TABLE table_ex
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3, field4);

它使用 MySQL 客户端程序和 PHP 应用程序工作.通过这种方式,它将在我的 MySQL 安装的数据目录中查找该文件.

It works using the MySQL client program and a PHP application. In this way it will look for the file in the Data Directory of my MySQL installation.

现在,如果我尝试使用 LOCAL 选项执行指令,它仅在我使用 mysql 客户端时才有效,而在 PHP 中无效:

Now if I try to execute the instructions using the LOCAL option, it only works if I use the mysql client, but not from PHP:

LOAD DATA LOCAL INFILE 'path/to/file/file.txt'
INTO TABLE table_ex
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3, field4);

再次.. 它适用于 MySQL 客户端,但不适用于 PHP 应用程序...我收到此错误:

Again.. it works with MySQL client but not from the PHP application... I get this error:

LOAD DATA LOCAL INFILE forbidden in /path/to/my/application

我读到问题与PHP的编译和使用mysqlnd有关.我使用的是 PHP 5.3.8 和 MySQL 5.5.15,但我还没有找到解决方案.

I read that the problem is related to the compilation of PHP and using mysqlnd. I am using PHP 5.3.8 and MySQL 5.5.15, but I haven't found a solution.

附加信息:到目前为止,我发现的唯一帮助是打开 PHP 错误:

Additional information: until now the only help I've found was an open PHP bug:

推荐答案

检查文档 http://php.net/manual/en/ref.pdo-mysql.php.

基本上你需要:

PDO::MYSQL_ATTR_LOCAL_INFILE => true

在实例化时设置.

示例:

    $conn = new \PDO("mysql:host=$server;dbname=$database;", "$user", "$password", array(
        PDO::MYSQL_ATTR_LOCAL_INFILE => true,
    ));

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

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