|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54158 MYSQLND + PDO MySQL requires #define MYSQL_OPT_LOCAL_INFILE
Submitted: 2011-03-04 01:18 UTC Modified: 2011-09-09 07:03 UTC
Avg. Score:4.6 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:3 (60.0%)
From: tamas at ideaweb dot hu Assigned: mysql (profile)
Status: Closed Package: PDO related
PHP Version: 5.3.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tamas at ideaweb dot hu
New email:
PHP Version: OS:


 [2011-03-04 01:18 UTC] tamas at ideaweb dot hu

On php 5.3.x PDO LOAD DATA LOCAL INFILE support seems broken. Running the code below issues a warning: 

Warning: PDOStatement::execute(): LOAD DATA LOCAL INFILE forbidden in /home/tamas/percona/load3.php on line 17  

This is coming from mysqlnd when CLIENT_LOCAL_FILES option is disabled. Looking at the trace file, PDO doesn't call mysql_options (set_client_option) to enable local infile support. I tracked down this is caused by the following ifdef in ext/pdo_mysql/mysql_driver.c:

if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE, (const char *)&local_infile)) {
goto cleanup;

MYSQL_OPT_LOCAL_INFILE is undefined hence the whole block which would enable local infile support is disabled. When the  ifdef/endif line is commented out everything works. I also tested with mysqli, that is unaffected and works as expected.

And a related bug to this one:

Configure Command =>  './configure'  '--prefix=/home/tamas/percona/php53dbg' '--disable-all' '--with-pdo-mysql=mysqlnd' '--enable-debug' '--enable-pdo' '--with-mysqli=mysqlnd' '--with-mysql=mysqlnd'



Test script:

$sql =  'LOAD DATA LOCAL INFILE \'/home/tamas/percona/\' INTO TABLE mail_message '.
    '(priority, user_id, `to`, template_id, data, custom_text_hash, spam)';

                     PDO::MYSQL_ATTR_LOCAL_INFILE => 1, 
$stmt = $con->prepare($sql);  



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-04 10:21 UTC]
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: mysql
 [2011-03-04 10:21 UTC]
to be fixed after 5.3.6 is released
 [2011-04-03 01:08 UTC] anthon dot pang at gmail dot com
As a workaround, I use PDO::ATTR_EMULATE_PREPARES. With 5.2.17 and 5.3.6 (using mysqlndb), both LOAD DATA INFILE and LOAD DATA LOCAL INFILE work on my Ubuntu 10.04 box, using PDO_MYSQL and MYSQLI extensions.
 [2011-04-03 03:57 UTC] anthon dot pang at gmail dot com
Sorry, you're right.  My "workaround" is actually because MySQL is compiled with --enable-local-infile.
 [2011-09-02 13:53 UTC]
Automatic comment from SVN on behalf of andrey
Log: Fix for Bug #54158 MYSQLND + PDO MySQL requires #define MYSQL_OPT_LOCAL_INFILE
and a bunch of other small preprocessor fixes
 [2011-09-09 07:03 UTC]
-Status: Analyzed +Status: Closed
 [2011-09-09 07:03 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

 [2011-10-18 16:35 UTC] richardpq at gmail dot com
I don't get it, after 5.3.6 release was working? because I have 5.3.8 and it is 
no working
 [2011-10-20 12:57 UTC] denis_truffaut at hotmail dot com
Some bug fix is planned for PHP 5.4 :

- PDO MySQL driver:
  . Fixed bug #54158 (MYSQLND+PDO MySQL requires #define MYSQL_OPT_LOCAL_INFILE)
 [2012-01-15 00:31 UTC] denis_truffaut at hotmail dot com
I just compiled PHP 5.4 RC5, on a Debian 6... and the bug is still there :(
 [2012-01-15 03:20 UTC] denis_truffaut at hotmail dot com
ext/pdo_mysql/mysql_driver.c, line 635 :

if (mysql_options(H->sergedit ver, MYSQL_OPT_LOCAL_INFILE, (const char 
*)&local_infile)) {

Should be

local_infile = 1;
if (mysql_options(H->sergedit ver, MYSQL_OPT_LOCAL_INFILE, (const char 
*)&local_infile)) {

You can achieve this dirty and quickly in doing :

sudo sed -ie 's/if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE/local_infile 
= 1;if (mysql_options(H->server, MYSQL_OPT_LOCAL_INFILE/g' 
 [2013-08-02 13:49 UTC] chris dot de dot kok at gmail dot com
I still seem to have this problem on: PHP 5.4.17-1~precise+1
Ubuntu 12.04
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC