【发布时间】:2015-11-07 23:10:43
【问题描述】:
由于某种原因,此代码导致 odbc_execute(); 尝试打开文件...
$file = fopen('somefile.csv', 'r');
fgetcsv($file); // Skip the first line
$data = [];
while (($line = fgetcsv($file)) != false) {
$data[] = $line;
}
fclose($file);
try {
$conn = odbc_connect("Teradata", "User", "Pass");
odbc_autocommit($conn, false);
odbc_exec($conn, 'DELETE FROM table');
foreach ($data as &$test) {
$stmt = odbc_prepare($conn, 'INSERT INTO table (experiment_code, experiment_name, variant_code, variant_name, version_number, report_start_date, report_end_date, status, transaction_date, experiment_test_id, test_manager, product_manager, pod, created_date, last_updated_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');
odbc_execute($stmt, $test);
}
odbc_commit($conn);
$result = odbc_exec($conn, 'SELECT * FROM table');
odbc_result_all($result);
} catch (Exception $e) {
odbc_rollback($conn);
echo $e->getMessage();
}
这是 CSV 文件的片段...
H1225,Some random text,H1225:001.000,Control,3,02/06/2014,03/31/2014,Completed,,HMVT-1225,Some random name,Some random name,Checkout,03/31/2014 16:54,02/06/2014 16:38
H1225,Some random text,H1225:001.000,Control,3,02/06/2014,03/31/2014,Completed,,HMVT-1225,Some random name,Some random name,Checkout,03/31/2014 16:54,02/06/2014 16:38
这是我遇到的错误类型...
Warning: odbc_execute(): Can't open file Control in C:\wamp\www\HEXinput\assets\php\dumpCSV.php on line 19
我得到相同错误的多个版本,只是文件名不同。文件名似乎来自第 3 列(基于 0)。另一个奇怪的事情是它实际上确实正确地插入了一些行。
我得到的最后一个错误是......
Fatal error: Maximum execution time of 120 seconds exceeded in C:\wamp\www\HEXinput\assets\php\dumpCSV.php on line 27
我在 Windows 7 64 位上使用版本 15 的 Teradatas ODBC 驱动程序。
这可能是什么原因造成的?
【问题讨论】:
-
你确定 csv 格式正确吗? “一些随机文本”看起来并不乐观。如果其中包含任何
,,您将丢弃该数组,因为 csv 解析器发现“更多”字段比实际应有的字段。 -
我相信它是.. 我怎么能仔细检查?
-
echo count($line)并查看所有行的计数是否相同。任何错误解析几乎肯定会导致这种情况发生。 -
不,所有行的计数都相同,均为 15
-
我已经稍微补充了我的问题,因为我注意到它总是在第 3 列,如果正在谈论基于 0...