LOAD DATA LOCAL INFILE forbidden in… PHP

后端 未结 12 1089
无人共我
无人共我 2020-12-01 10:38

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

Here are some details

If I use this i

相关标签:
12条回答
  • 2020-12-01 10:52

    According to the MySQL manual MySQL must be compiled with --enable-local-infile. From a comment at that link:

    You MUST have compiled PHP using the full path to MySQL, otherwise it will use it's internal handlers, which don't work with the "new" LOAD DATA.

    --with-mysql=/usr/local/mysql (assuming your MySQL is located here)

    You MUST start the MySQL daemon with the option '--local-infile=1'

    0 讨论(0)
  • 2020-12-01 10:52

    If you use an Ubuntu server, you can try to install php5-mysqlnd :

    sudo apt-get install php5-mysqlnd

    0 讨论(0)
  • 2020-12-01 10:57

    Check docs http://php.net/manual/en/ref.pdo-mysql.php.

    Basically you need:

    PDO::MYSQL_ATTR_LOCAL_INFILE => true
    

    Set at instantiation.

    Example:

        $conn = new \PDO("mysql:host=$server;dbname=$database;", "$user", "$password", array(
            PDO::MYSQL_ATTR_LOCAL_INFILE => true,
        ));
    
    0 讨论(0)
  • 2020-12-01 10:57

    To resolve the same problem in PHP Symfony application, this flag needs to be enabled in the yml config file. Here is an example:

    # Doctrine Configuration
    doctrine:
        dbal:
            driver:   pdo_mysql
            options:
                !php/const PDO::MYSQL_ATTR_LOCAL_INFILE: true
            # Skip the rest
    

    Also note how to reference PHP constant here in yml file, and this format is used for Symfony 3.4. For older version, check out Symfony doc.

    0 讨论(0)
  • 2020-12-01 10:58

    I had exactly the same problem on a EC2 Ubuntu 12.04 LTS instance when accessing a MySQL on RDS: LOAD DATA LOCAL INFILE... works fine on a mysql console but not from PHP. Accidentaly i found out that it worked fine on another almost identical machine that used MariaDB (a binary compatible drop in replacement for MySQL).

    So i replaced the MySQL clients with the ones from MariaDB and it worked.

    0 讨论(0)
  • 2020-12-01 10:59

    Easiest solution, that may work on some servers is to remove LOCAL like:

    Original:LOAD DATA LOCAL INFILE New/ It should be: LOAD DATA INFILE

    Strange, but I have found this solution to work on my local machine, with xampp but it did not work on a live server with CentOS, so I'd to revert the code back and add 'LOCAL'.

    0 讨论(0)
提交回复
热议问题