SHARE
TWEET

Untitled

a guest Sep 13th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use Goodby\CSV\Export\Standard\Exporter;
  2. use Goodby\CSV\Export\Standard\ExporterConfig;
  3. use Goodby\CSV\Export\Standard\CsvFileObject;
  4. use Goodby\CSV\Export\Standard\Collection\PdoCollection;
  5. use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
  6.  
  7. require_once("vendor/autoload.php");
  8.  
  9. //DBの設定(postgreSQLの場合)
  10. $pdo = new PDO('pgsql:host=localhost;dbname=hoge', 'postgres', '');
  11.  
  12. $stmt = $pdo->prepare("SELECT * FROM users");
  13. $stmt->execute();
  14.  
  15. $collection = new CallbackCollection(new PdoCollection($stmt), function($row) {
  16.     //ここにデータの処理など
  17.     $row['name'] = strtoupper($row['name']);
  18.  
  19.     return $row;
  20. });
  21.  
  22. //configの設定 SJISで出力する
  23. $config = new ExporterConfig();
  24. $config->setToCharset('SJIS-win');
  25.  
  26. //エクスポート
  27. $exporter = new Exporter($config);
  28. $exporter->export('users_converted.csv', $collection);
RAW Paste Data
Top