If I use a Load Data Infile MySQL query in PHP, where is the file location relative to? Is it the same folder as the PHP file?
The LOAD DATA INFILE statement reads rows from a text file into a table at a very high speed. If the LOCAL keyword is specified, the file is read from the client host. If LOCAL is not specified, the file must be located on the server.
In case if Mysql 5.7 you can use "show global variables like "local_infile" ;" which will give the local infile status ,You can turn it on using "set global local_infile=ON ; ". Show activity on this post.
Using the LOAD DATA statement, you can insert the contents of a file (from the server or a host) into a MySQL table. If you use the LOCAL clause, you can upload the local files contents int to a table.
Using the LOCAL modifier with the LOAD DATA INFILE statement, you can import file from the client (local computer) to a remote MySQL database server. Here, the client program reads the file present on the client and sends it to the desired remote MySQL Database Server.
With LOAD DATA INFILE
, the file name is relative to the server.
With LOAD DATA LOCAL INFILE
, the file is relative to the client.
If both server and client reside on the same machine, you shold use LOAD DATA INFILE
, because it can handle key violations and other errors much more nicely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With