首页 > 解决方案 > 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();

?>

标签: phpsymfonyexportexport-to-csvsymfony4

解决方案


推荐阅读