Home > Database > Mysql Tutorial > body text

Why Does \'LOAD DATA LOCAL INFILE\' Fail in PHP and How to Fix It?

Susan Sarandon
Release: 2024-11-03 15:38:30
Original
547 people have browsed it

Why Does

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template