0

I am trying to upload a csv file into my mysql database from php code. I am getting an error: "Could not updated:The used command is not allowed with this MySQL version"

This is the code I am using. Do i have to give any kinds of permissions so that I am able to do it from php forms.? As I am able to load this same csv file from mysql directly from terminal.

P.S.:- I have changed my.cnf file after reading this post. MySQL: Enable LOAD DATA LOCAL INFILE

How ever i am unable to upload from phpmyadmin and from php forms. Error Message is same. i.e. "Could not updated:The used command is not allowed with this MySQL version"

Below is the piece of code.

if(@$_POST['submit'])
{
    $file = $_FILES['file'];
    $name = $file['name'];
    $type = $file['type'];
    $size = $file['size'];
    $tmppath = $file['tmp_name']; 
    echo "Name of the file is $name <br> $tmppath";
    if($name!="")
    {
        echo "<br> Trying to upload file <br>";         
        if(move_uploaded_file($tmppath, "csvfiles/.$name")) //project is a folder in which you will save csv files
        {
            $query="LOAD DATA LOCAL INFILE '$tmppath' INTO TABLE test.metadata FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 1 LINES;";
            mysql_query ($query) or die ('Could not updated:'.mysql_error());
            echo "CSV file inserted successfully !!<br>";
        }else {echo "<br>Failed !!!!";}
    }else {echo "<br>No file exist <br>";}
}else {echo " <br> No file exist <br>";}
Community
  • 1
  • 1
Ameya
  • 69
  • 2
  • 10

1 Answers1

0

If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts to issue such a statement receives the following error message:

ERROR 1148: The used command is not allowed with this MySQL version

Try to run below in if UNIX

mysql_fix_privilege_tables --password=root_password

or if windows

C:\> cd "C:\Program Files\MySQL\MySQL Server 5.0"
C:\> bin\mysql -u root -p mysql
mysql> SOURCE share/mysql_fix_privilege_tables.sql
Yogus
  • 2,307
  • 5
  • 20
  • 38
  • I am using ubuntu 12.4 and when I run mysql_fix_privilege_tables --password=root_password it gives me error command not found. – Ameya May 27 '13 at 10:27
  • Can you run `mysql_upgrade` – Yogus May 27 '13 at 10:49
  • I got this error. Could not create the upgrade info file '/var/lib/mysql/mysql_upgrade_info' in the MySQL Servers datadir, errno: 13 – Ameya May 27 '13 at 11:33
  • I did it using superuser, It is upgraded now. – Ameya May 27 '13 at 11:36
  • Nope, the upgrade did not work, I guess coz I am getting the same error when i try to load the file from php form. – Ameya May 27 '13 at 11:46
  • Well I have solved the issue guys/girls, used fgetcsv() instead of LOAD LOCAL DATA... Thanks to everyone.... – Ameya May 30 '13 at 12:36