我正在尝试将 CSV 文件自动导入 MySQL。我以为我可以在我的服务器上将 PHP 文件作为 cronjob 运行,因为 PHPMyAdmin 没有启用事件(并且不可能是由于网络主机)。我一直在尝试使用 LOAD DATA Syntax,当我在谷歌上搜索这个问题并在 Stack Overflow 上遇到 5000 万个线程时,它似乎很受欢迎。但是,我在调试自己的配置时遇到了麻烦,并且很沮丧,因为我无法找到一种方法来显示错误以帮助找出我做错了什么。我知道我的 CSV 文件变量是正确的,因为我有一个代码来检查它并且它通过了(我也故意让它失败并且失败了,所以肯定有效):$file = fopen($csvfile,"r");if (!$file) { echo "<h1>bachHa'!</h1><p>Error opening data file.</p>\n"; exit;}所以,我知道我已经找到了我的 CSV 文件并且我正确地将它传递给了 LOAD DATA,但是在那之后,谁知道呢,我所知道的是我的数据库在运行后没有得到任何东西:$import = <<<eof LOAD DATA LOCAL INFILE '$csvfile' INTO TABLE test_upload FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (response_id,date_submitted,status,q1,q5_text,q2,q3,q4_1,q4_2,q4_3,q4_4,q4_5,StoreName);eof;$conn->query($import);列标题是准确的,我的数据文件与它们对齐,空列允许为 NULL。我已经浏览了手册,但找不到一种方法来获取错误以显示在我的 PHP 文件中,回显$import看起来很好并且$conn没有回显任何内容(不确定是否应该,我不是程序员并且只是想通过这件事来解决我的问题)。csv文件示例:"Response ID","Date Submitted","Status","Q01","Q05","Q02","Q03","Q04_01","Q04_02","Q04_03","Q04_04","Q04_05","StoreName""62","2019/05/06 16:43:59","Complete","8","","8","No","Very good","Good","Very good","Good","Very good","Store A""63","2019/05/06 16:45:36","Complete","10","I had a very nice experience with a lady called Karen she was very helpful","10","Yes","Very good","Good","Good","Good","Very good","Store C"任何帮助都非常受欢迎!
1 回答
- 1 回答
- 0 关注
- 155 浏览
添加回答
举报
0/150
提交
取消