PHP LOAD DATA LOCAL INFILE Limitation
When attempting to execute a LOAD DATA statement with the LOCAL option from a PHP application, users may encounter the error "LOAD DATA LOCAL INFILE forbidden." This issue arises due to a PHP compilation issue and the use of the mysqlnd driver.
Resolving the Issue
The solution lies in enabling the LOCAL INFILE attribute through the PDO object instantiation. This can be achieved by setting the PDO::MYSQL_ATTR_LOCAL_INFILE parameter to true at the time of instantiation.
Example
<code class="php">$conn = new \PDO("mysql:host=$server;dbname=$database;", "$user", "$password", array( PDO::MYSQL_ATTR_LOCAL_INFILE => true, ));</code>
By implementing this setting, PHP applications can successfully execute LOAD DATA LOCAL INFILE statements.
The above is the detailed content of Why Does \'LOAD DATA LOCAL INFILE\' Fail in PHP and How to Fix It?. For more information, please follow other related articles on the PHP Chinese website!