user2671011 user2671011 - 2 months ago 28
PHP Question

SQLSTATE[42000]: Syntax error or access violation: 1148 The used command is not allowed with this MySQL version

I am trying to upload complete CSV file in Laravel code looks like this

public function testfastupload(Request $request)
{
$file = Flag::where('imported','=','0')
->orderBy('created_at', 'DESC')
->first();
$file_path = Config::get('filesystems.disks.local.root') . '/' .$file->file_name;


$query = "LOAD DATA LOCAL INFILE '" . $file_path . "'
INTO TABLE testdb
(name,
phone,
dob,
addresse,
@created_at,
@updated_at)
SET created_at=NOW(),updated_at=null";

DB::connection()->getpdo()->exec($query);
}


I am getting error as follows


SQLSTATE[42000]: Syntax error or access violation: 1148 The used
command is not allowed with this MySQL version


I have also installed

sudo apt-get install php5-mysqlnd


The error report looks like this

`at PDO->exec('LOAD DATA LOCAL INFILE '/var/www/testUploadExcelApp/uploadExcel/storage/app/379ea12c68e382a438592b4da305a3c2.csv' INTO TABLE testdb (name, phone, dob, addresse, @created_at, @updated_at) SET created`_at=NOW(),updated_at=null') in ExcelhandellerController.php line 113


Can any one help me out

Answer

Add 'options' => [PDO::MYSQL_ATTR_LOCAL_INFILE=>true], to your connection in config/database.php . This will enable the local infile option, which is off by default.