I have a php web page that let's a person upload a file. I want to extract the file name from $_FILE and then load all the data into my database.
My code looks like this:
$myfile = $_FILE['file']['tmp_file'];
$executebatchloadsql = 'LOAD DATA LOCAL INFILE "'. $myfile .'" INTO TABLE testtable (fname, lname);
mysql_query($executebatchloadsql) or die(mysql_error());
But the error message I'm getting says:
The used command is not allowed with this MySQL version
My questions are as follows
- Am I supposed to use the
tmp_file
name or the name? - What do I need to do to get the load data command to work? I've tried to follow the post found at MySQL: Enable LOAD DATA LOCAL INFILE but it's still giving me the same error.
EDIT 1:
This is what my /etc/mysql/my.cnf looks like in part:
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
local-infile
The last line is what I added. I also added the same line to the [mysql] section:
[mysql]
local-infile
After making these changes, I restarted sql:
/etc/init.d/mysql restart
But I'm still having the problem
EDIT 2:
I've also tried local-infile=1 as per the same post I mention above. But that doesn't work either.
EDIT 3
I've tried to add the FILE prvil to the user.. like so:
GRANT FILE ON *.* TO root;
and then when i showit grants for root, i can see that its been added. but i'm still getting an error message that the used command is not allowed on my version of mysql. Do I need the "=1" after the infile in my my.cfg file?
EDIT 4:
As a further test, i tried loading the file manually via command line instead of via php and it accepted it. I logged in as root (which is the same id i'm using my app for testing purposes) and then I tried the following command:
mysql> load data local infile '/var/www/testwebsite/abc.csv' into table testtable;
Query OK, 3 rows affected, 48 warnings (0.00 sec)
Records: 3 Deleted: 0 Skipped: 0 Warnings: 48
But I can't seem to get the PHP code working. Thanks.!