I need to know what to replace this code with after updating to MYSQL 8 [duplicate]

This question already has answers here: ERROR: Loading local data is disabled - this must be enabled on both the client and server sides (15 answers) Closed 18 hours ago. This code is part of what is used to import data from a text file to a WordPress database: mysqli_query($cons, ' LOAD DATA LOCAL INFILE "'.$file.'" REPLACE INTO TABLE '.$table.' FIELDS TERMINATED by \'\t\' LINES TERMINATED BY \'\n\' IGNORE 1 LINES; ')or die(mysqli_error($cons)); Now after an update to MYSQL 8, we are getting this error: Loading local data is disabled; this must be enabled on both the client and server sides Our hosting confirmed that they recently did the MYSQL update so that is the culprit. I haven't really tried anything because I'm hesitant due to my non-expertness on the matter. I was wondering if there's a simple change that must be done to the mysqli_query declaration above for it to work without using "LOAD DATA LOCAL". I only worked on the data manipulation part of the code, not the part where it grabs data from the files so any help would be appreciated!

Comment (1)

Jese Leos

August 31, 2024

Verified user

To use LOAD DATA LOCAL INFILE both you and your database hosting provider need to set an option. For PHP with mysqli, you need to set the PHP variable mysqli.allow_local_infile=1. Note that this was already set to 1 by default in PHP prior to 7.2.2 and 7.3.3. But it's no longer the default in current PHP. See https://www.php.net/manual/en/mysqli.configuration.php So you may need to set this variable in you php.ini. I wouldn't be surprised if you have recently upgraded PHP as well as upgrading MySQL Server, because all PHP 7.x versions are now unsupported. In addition, on the MySQL Server side, your provider needs to enable the local_infile option in my.cnf. See https://dev.mysql.com/doc/refman/8.0/en/load-data-local-security.html for full explanation. Both of these options, one on the client and one on the server, must be enabled or else local file imports won't be allowed. That's the meaning of the error you saw: Loading local data is disabled; this must be enabled on both the client and server sides I think of it like those fancy missile-launch keys, where two people must independently turn their keys.

You’ll be in good company