doudun2212 2018-07-11 13:06
浏览 101
已采纳

Yii2 LOAD DATA LOCAL INFILE

I know there are other solutions to this problem, but it did not work for me.

I am trying to execute a LOAD DATA LOCAL INFILE statement in a MySQL database via a Yii2 website. I have got this working in the past, so I am not sure why it doesn't work anymore.

I get the following error:

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

I do have the following setting in my db.php config file.

'attributes' => [ PDO::MYSQL_ATTR_LOCAL_INFILE => true ],

I also tried disabling secure-file-priv to no avail.

EDIT

I tried running the following query from Workbench and it throws an error via Workbench as well. However, it works on MySQL 5.7. I am currently using 8.0

LOAD DATA LOCAL INFILE 'D:/Temp/6_attlog.dat' IGNORE
INTO TABLE att_log
FIELDS TERMINATED BY '\t' ENCLOSED BY '''' LINES TERMINATED BY '
' IGNORE 0 LINES 
(@id, `date_time`, `dev_id`, `mode`, `work_code`, `work_code1`) SET `id` = TRIM(@id)

EDIT 2

I got it to work with "LOAD DATA INFILE"...

...but it does not work with "LOAD DATA LOCAL INFILE"

Here's the code I was using...

$inFile = str_replace('\\', '/', realpath('uploads/'.$model->file->name));
Yii::$app->db->createCommand('
    LOAD DATA LOCAL 
    INFILE \''.$inFile.'\' IGNORE 
    INTO TABLE att_log 
    FIELDS TERMINATED BY \'\\t\'  
    ENCLOSED BY \'\'\'\' 
    LINES TERMINATED BY \'
\' 
    IGNORE 0 LINES 
    (@id, `date_time`, `dev_id`, `mode`, `work_code`, `work_code1`) 
    SET `id` = TRIM(@id)
')->execute();
unlink($inFile);
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Materials studio8.0报错怎么解决(关键词-错误信息)
      • ¥20 vb6.0窗体中的vscroll控件无法响应鼠标滚轮事件,请教方法
      • ¥15 如何在linux服务器做视频静态资源访问接口
      • ¥15 Python Xpath对<em>标签的爬取结果变成了- -(关键词-Xpath)
      • ¥15 el-cascader懒加载模式选中单选框加载下层无数据问题
      • ¥15 promql 参数怎么忽视大小写查询
      • ¥50 swift使用textkit读取大文本文件速度慢的问题
      • ¥20 统信linux360企业浏览器 如何配置扩展程序?(图形界面我知道)
      • ¥100 c/c++实现DoubleArrayTrie
      • ¥15 在开发/迭代一款企业信息软件时会耗费你们多长时间?