1

I got a problem when executing a LOAD DATA LOCAL INFILE via php.

PDOStatement::execute(): LOAD DATA LOCAL INFILE forbidden in /blablabla

Query is working with mysql directly, but it do no work with php.

I checked my local_infile from mysql, it is ok :

SHOW GLOBAL VARIABLES LIKE 'local_infile'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | local_infile | ON | +---------------+-------+ 1 row in set (0.00 sec)

There are some others questions about that but I can't modify source code (so PDO configuration in php code) : LOAD DATA LOCAL INFILE forbidden in... PHP

EDIT : I find how to configure pdo in my case, and I added PDO::MYSQL_ATTR_LOCAL_INFILE => true option in PDO.

I got an other error :

[13:10:16] SQLSTATE[42000]: Syntax error or access violation: 1148 The used command is not allowed with this MySQL version, query was: LOAD DATA LOCAL INFILE '/tmp/export_cat_28.csv' REPLACE INTO TABLE tmp_pimgento_entities_category FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES;

Query still work with mysql directly.

Any ideas ? Thanks.

Community
  • 1
  • 1
sdewasme
  • 21
  • 1
  • 4
  • What path you use exactly ? (i suppose it's not blabla^^). Can you try with use `dirname(__FILE__).'/'.Your_Path` please ? – Xenofexs Apr 08 '16 at 12:14
  • It is the path to my project. Here the full path : ```Warning: PDOStatement::execute(): LOAD DATA LOCAL INFILE forbidden in /home/soann-elosi/Documents/magento2project/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php on line 228``` – sdewasme Apr 08 '16 at 12:21
  • FILE privilege is set for mysql user? – Max P. Apr 08 '16 at 13:20
  • FILE privilege is set... :( – sdewasme Apr 08 '16 at 15:54
  • @SirBigoo have you solved this issue ? – fxbois May 03 '16 at 12:43
  • @fxbois No I don't. I reported an issue on the github's module which use that query. And the developper did not find out how to solve this, but it seems like a PHP bug. He commited a fix to remove the LOCAL keyword. I guess it's the only solution... – sdewasme May 07 '16 at 18:42
  • @SirBigoo I've solved this using `mysqli_init()`, `$link->options(MYSQLI_OPT_LOCAL_INFILE, true)` and `$link->real_connect()` (instead of `new mysqli()`) – fxbois May 08 '16 at 21:40

1 Answers1

11
$pdo = new PDO(
    'mysql:host=hostname;dbname=ssldb',
    'username',
    'password',
    [PDO::MYSQL_ATTR_LOCAL_INFILE => true]
);
Jacek Krysztofik
  • 1,266
  • 1
  • 13
  • 29