Rumah >php教程 >php手册 >PDO导入CSV,”LOAD DATA LOCAL INFILE”报错解决

PDO导入CSV,”LOAD DATA LOCAL INFILE”报错解决

WBOY
WBOYasal
2016-06-06 20:12:431785semak imbas

本地wamp导入csv无报错代码: LOAD DATA INFILE '/opt/htdocs/www/xxx.com/xxx/public/upload/53a7d83f00e08b4f0121d80f.csv' REPLACE INTO TABLE newcardCHARACTER SET utf8FIELDS TERMINATED BY '' ENCLOSED BY '\"'LINES TERMINATED BY '\r\n' (`code`) 传

本地wamp导入csv无报错代码:

LOAD DATA INFILE  '/opt/htdocs/www/xxx.com/xxx/public/upload/53a7d83f00e08b4f0121d80f.csv' REPLACE INTO  TABLE newcard
CHARACTER SET utf8
FIELDS TERMINATED BY '' ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n' (`code`)

传到服务器上的时候报

Access denied.

后来查了下原因是由于数据库服务器和文件服务器不在同一台机器上需要使用”LOAD DATA LOCAL INFILE”.

于是将代码改成

LOAD DATA LOCAL INFILE  '/opt/htdocs/www/xxx.com/xxx/public/upload/53a7d83f00e08b4f0121d80f.csv' REPLACE INTO  TABLE newcard
CHARACTER SET utf8
FIELDS TERMINATED BY '' ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n' (`code`)

Warning: PDO::exec(): LOAD DATA LOCAL INFILE forbidden in /opt/htdocs/www/xxx.com/xxx/public/test.php on line 12

后来google了一下,在load-data-local-infile-forbidden-in-php有解决方案

在pdo初始化的时候传入以下参数即可解决问题

\PDO::MYSQL_ATTR_LOCAL_INFILE => true

转载请注明:Jesus.Pan的博客 » PDO导入CSV,”LOAD DATA LOCAL INFILE”报错解决

PDO导入CSV,”LOAD DATA LOCAL INFILE”报错解决,首发于Jesus.Pan的博客。

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:Laravel(1)-WIN7安装4.2Artikel seterusnya:给PHP增加函数强制类型返回