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

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

WBOY
Release: 2016-06-06 20:12:43
Original
1751 people have browsed it

本地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`)
Copy after login

传到服务器上的时候报

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`)
Copy after login

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
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template