php - 如何通过 ajax 将数百万行从 DB 导出到 CSV?
问题描述
我的数据库中有数百万行。我需要将它们全部导出到 csv 文件中。问题是我有超时限制错误。
所以。我决定通过ajax来做。
我创建了生成几个 tmp csv 文件的 ajax
function chunkedExport()
{
$.ajax({
type: "POST",
url: "transactions/",
dataType: "JSON",
data: $("#transactions").serialize(),
async: false,
success: function(response)
{
if (response.status === "continue")
{
$("#start_from").val(response.start_from);
$("#client_file_name").val(response.client_file_name);
$("#file_name").val(response.tmp_file_name);
$("#step").val(response.step);
chunkedExport();
} else {
console.log('DOWNLOAD');
$("#start_from").val(0);
$("#client_file_name").val('');
$("#file_name").val('');
$("#step").val(1);
$("#export_type").val("");
$('#csv_format').val("");
document.location.href = '/transactions_export_csv/'+response.client_file_name+'/'+response.tmp_file_name+'/'+response.total_iterations+'/'
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log([xhr, ajaxOptions, thrownError]);
$("#start_from").val(0);
$("#client_file_name").val('');
$("#file_name").val('');
$("#step").val(1);
$("#export_type").val("");
$('#csv_format').val("");
}
});
}
问题是如何将它们全部合并到一个 csv 文件中并下载?
解决方案
推荐阅读
- node.js - 工作代码完成后NodeJS没有代码运行
- colors - 是否可以在 MediaWiki 中将页面链接的颜色更改为红色?
- css - 有没有办法将 sass 项目转换为 css(不仅仅是编译 sass)?
- python - 为什么我无法在 Python 中使用 Pandas 导入数据?
- rust - 错误:与 `cc` 链接失败:退出代码:1 for cargo run
- postgresql - Linux Mint 20.2 - 无法构建 plv8:subprocess.CalledProcessError #451
- firebase - Firebase (Cloud Functions) - 编译具有视频稳定功能的 FFmpeg (vidstab)
- android - 使用 Appium 进行移动应用自动化测试
- r - 如何在 R 中创建汇总表
- typo3 - Friendsofsymfony/rest-bundle 和 TYPO3