【发布时间】:2012-03-14 22:06:24
【问题描述】:
我正在尝试了解如何编写查询以将我的 goodreads.com 图书列表 (csv) 导入我自己的数据库。我正在使用 PHP。
$query = "load data local infile 'uploads/filename.csv' into table books
RETURN 1 LINES
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(Title, Author, ISBN)";
这导致数据在错误的列中,我也无法获取 ISBN,无论我尝试什么,猜测等号 (=) 会导致一些问题。
这是 CSV 的前两行:
Book Id,Title,Author,Author l-f,Additional Authors,ISBN,ISBN13,My Rating,Average Rating,Publisher,Binding,Number of Pages,Year Published,Original Publication Year,Date Read,Date Added,Bookshelves,Bookshelves with positions,Exclusive Shelf,My Review,Spoiler,Private Notes,Read Count,Recommended For,Recommended By,Owned Copies,Original Purchase Date,Original Purchase Location,Condition,Condition Description,BCID
11487807,"Throne of the Crescent Moon (The Crescent Moon Kingdoms, #1)","Saladin Ahmed","Ahmed, Saladin","",="0756407117",="9780756407117",0,"3.87","DAW","Hardcover","288",2012,2012,,2012/02/19,"to-read","to-read (#51)","to-read",,"",,,,,0,,,,,
我想要做的只是将所有书籍的标题、作者和 ISBN 导入到具有以下字段的表中:id (auto)、title、author、isbn。我也想排除第一行,因为我不想要列标题,但是当我尝试时它每次都失败。
我的查询有什么问题?
【问题讨论】: