禁止在...中加载数据本地文件 [英] LOAD DATA LOCAL INFILE forbidden in... PHP

查看:84
本文介绍了禁止在...中加载数据本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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,
    ));

这篇关于禁止在...中加载数据本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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