php - PHP Symfony 4 导出 CSV
问题描述
我尝试为我的网站创建 CSV 导出功能。我收到错误:“传递给 _construct() 的参数必须是 PDOStatement 的实例”。以下是代码(php symfony 4) - 请告知。谢谢!
<?php
use Exporter\Handler;
use Exporter\Source\PDOStatementSourceIterator;
use Exporter\Writer\CsvWriter;
// Prepare the data source
$em=$this-getDoctrine()->getManager();
$sql="select id, name from table";
$stm= $em->getConnection()->prepare($sql);
$stm->execute();
$source = new PDOStatementSourceIterator($stm);
// Prepare the writer
$writer = new CsvWriter('data.csv');
// Export the data
Handler::create($source, $writer)->export();
?>
解决方案
推荐阅读
- javascript - 为什么 CSS 在不同的页面大小上无法正常工作
- c# - 在 C# 中使用 SELECT 插入表时出现 Oracle 错误
- javascript - 如何在嵌入视频的末尾添加缩略图?
- android - 导航抽屉中的Android,在当前片段中调用方法
- java - 使用反射在 Java Map 中设置或获取数组
- python - 无论顺序如何,在 2 个列表之间查找共同元素 - python 2
- reactjs - React-Router Redirect 只渲染组件的一部分
- angular - Angular 如何在可扩展的 ngIf 模板表单中维护 ngModel 字段
- angular - 用角度创建一个新项目
- sql-server - AZURE SQL MI 错误:由于数据库关闭,数据库 id '10' 的陈旧/中止版本清理被中止