Home  >  Article  >  Database  >  How to Resolve \"LOAD DATA LOCAL INFILE Permission Denied\" in PHP?

How to Resolve \"LOAD DATA LOCAL INFILE Permission Denied\" in PHP?

Linda Hamilton
Linda HamiltonOriginal
2024-11-06 02:11:02605browse

How to Resolve

LOAD DATA LOCAL INFILE Permission Denied in PHP

When using LOAD DATA INFILE with the LOCAL option, users may encounter permission errors when accessing the file from PHP applications. This issue is attributed to the compilation settings of PHP and the use of mysqlnd.

To resolve this problem, users can set the PDO::MYSQL_ATTR_LOCAL_INFILE attribute to true during PDO instantiation:

<code class="php">$conn = new \PDO("mysql:host=$server;dbname=$database;", "$user", "$password", array(
    PDO::MYSQL_ATTR_LOCAL_INFILE => true,
));</code>

By enabling this attribute, PHP will be granted permission to access local files when executing the LOAD DATA LOCAL INFILE command. This allows users to conveniently load data into MySQL tables from files located on the server.

The above is the detailed content of How to Resolve \"LOAD DATA LOCAL INFILE Permission Denied\" in PHP?. 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