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

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

WBOY
WBOY原创
2016-06-06 20:12:431746浏览

本地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的博客。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn