Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Goodby\CSV\Export\Standard\Exporter;
- use Goodby\CSV\Export\Standard\ExporterConfig;
- use Goodby\CSV\Export\Standard\CsvFileObject;
- use Goodby\CSV\Export\Standard\Collection\PdoCollection;
- use Goodby\CSV\Export\Standard\Collection\CallbackCollection;
- require_once("vendor/autoload.php");
- //DBの設定(postgreSQLの場合)
- $pdo = new PDO('pgsql:host=localhost;dbname=hoge', 'postgres', '');
- $stmt = $pdo->prepare("SELECT * FROM users");
- $stmt->execute();
- $collection = new CallbackCollection(new PdoCollection($stmt), function($row) {
- //ここにデータの処理など
- $row['name'] = strtoupper($row['name']);
- return $row;
- });
- //configの設定 SJISで出力する
- $config = new ExporterConfig();
- $config->setToCharset('SJIS-win');
- //エクスポート
- $exporter = new Exporter($config);
- $exporter->export('users_converted.csv', $collection);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement