Home >Database >Mysql Tutorial >Why Does \'LOAD DATA LOCAL INFILE\' Fail in PHP and How to Fix It?

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

Susan Sarandon
Susan SarandonOriginal
2024-11-03 15:38:30571browse

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>

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!

Statement:
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