{"id":31863839,"url":"https://github.com/sujancse/php-csv-exporter","last_synced_at":"2025-10-12T18:57:35.935Z","repository":{"id":57061142,"uuid":"234065299","full_name":"sujancse/php-csv-exporter","owner":"sujancse","description":"A fast and tiny PHP library to export data to CSV based on Generator. Export millions of data seamlessly without memory exception.  ","archived":false,"fork":false,"pushed_at":"2022-10-31T08:07:08.000Z","size":28,"stargazers_count":19,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-25T22:55:26.246Z","etag":null,"topics":["csv","csv-exporter-based-on-generator","export","export-csvfile","export-to-excel","export-without-memory-exception","exporter","fast-csv-exporter","laravel-csv-export","php-export-to-csv","php-xlsx","seamless-export","xlsx"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sujancse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-15T11:27:28.000Z","updated_at":"2025-05-19T10:53:40.000Z","dependencies_parsed_at":"2022-08-24T07:30:48.110Z","dependency_job_id":null,"html_url":"https://github.com/sujancse/php-csv-exporter","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/sujancse/php-csv-exporter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sujancse%2Fphp-csv-exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sujancse%2Fphp-csv-exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sujancse%2Fphp-csv-exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sujancse%2Fphp-csv-exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sujancse","download_url":"https://codeload.github.com/sujancse/php-csv-exporter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sujancse%2Fphp-csv-exporter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279012519,"owners_count":26085135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","csv-exporter-based-on-generator","export","export-csvfile","export-to-excel","export-without-memory-exception","exporter","fast-csv-exporter","laravel-csv-export","php-export-to-csv","php-xlsx","seamless-export","xlsx"],"created_at":"2025-10-12T18:57:34.880Z","updated_at":"2025-10-12T18:57:35.930Z","avatar_url":"https://github.com/sujancse.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Packagist Version](https://img.shields.io/packagist/v/sujan/php-csv-exporter)\n![Packagist](https://img.shields.io/packagist/dt/sujan/php-csv-exporter?color=green)\n![GitHub](https://img.shields.io/github/license/sujancse/php-csv-exporter?color=yellow)\n\n## Overview\nA fast and tiny PHP library to export data to CSV. The library is based on a PHP generator.\n\n## Why Use\nIt took me 5 seconds to export 5M data so you can call it fast enough. And because of the use of \n[Generator](https://www.php.net/manual/en/language.generators.overview.php) it uses less memory \nand never get caught by memory exception.\n\n### Installation\n```$xslt\ncomposer require sujan/php-csv-exporter\n```\n\n## Basic Usage\n```$xslt\n$columns = [ 'id', 'name', 'email' ];\n\n$queryBuilder = User::limit(10); // Query Builder\n\n$exporter = new Exporter();\n$exporter-\u003ebuild($queryBuilder, $columns, 'users.csv')\n         -\u003eexport();\n```\n\nBuild and export, that much simple.\n\n## Documentation\n\n - [Build CSV](#build-csv)\n - [Export CSV](#export-csv)\n - [Usage Examples](#usage-examples)\n    - [Laravel](#laravel) \n        - [From Eloquent Query Builder (RECOMMENDED)](#from-eloquent-query-builder-recommended) \n        - [From Collection](#from-collection) \n        - [From Array](#from-array) \n        - [Eloquent Relation](#eloquent-relation) \n    - [RAW PHP](#raw-php) \n        - [From Array](#from-plain-array) \n        - [From PDOStatement (RECOMMENDED)](#from-pdostatement-recommended)\n\n### Build CSV\nCSV build takes three parameters. First one is the model which could be `Array`, `PDOStatement`, `Eloquent Query Builder` and \n`Collection`, seconds one takes the field names you want to export, third one is CSV filename.\n\n```$xslt\n$exporter-\u003ebuild($queryBuilder, $columns, 'users.csv');\n```\n\n### Export CSV\n```$xslt\n$exporter-\u003eexport();\n```\n\n## Usage Examples\n### Laravel \nYou can export data from `Eloquent Query Builder`, `Collection` and `Array` whereas `Eloquent Query Builder` is highly recommended.\n#### From Eloquent Query Builder (RECOMMENDED)\n```$xslt\n$columns = [ 'id', 'name', 'email' ];\n\n$queryBuilder = User::latest()-\u003ewhereNotNull('email_verified_at'); // Query Builder\n\n$exporter = new Exporter();\n$exporter-\u003ebuild($queryBuilder, $columns, 'users.csv')\n         -\u003eexport();\n```\n\n#### From Collection\n```$xslt\n$columns = [ 'id', 'name', 'email' ];\n\n$collection = User::latest()-\u003eget(); // Collection\n\n$exporter = new Exporter();\n$exporter-\u003ebuild($collection, $columns, 'users.csv')\n         -\u003eexport();\n```\n\n#### From Array\n```$xslt\n$columns = [ 'id', 'name', 'email' ];\n\n$usersArray = User::latest()-\u003eget()-\u003etoArray(); // Array of Users\n\n$exporter = new Exporter();\n$exporter-\u003ebuild($usersArray, $columns, 'users.csv')\n         -\u003eexport();\n```\n\n#### Eloquent Relation\n```$xslt\n$columns = [\n    'id',\n    'title',\n    'user' =\u003e [ // user is a relation\n        'name'\n    ]\n];\n\n$queryBuilder = Post::with('user'); // Query builder\n\n$exporter = new Exporter();\n$exporter-\u003ebuild($queryBuilder, $columns, 'users.csv')\n         -\u003eexport();\n```\n\n### Raw PHP\nThe library supports Laravel as well as raw PHP. You can easily export data from `PDOStatement` and `Array`.\n\n#### From Plain Array\n```$xslt\n$array = [\n    ['id' =\u003e 1, 'name' =\u003e 'John Doe', 'email' =\u003e 'john@example.com'],\n    ['id' =\u003e 2, 'name' =\u003e 'Jane Doe', 'email' =\u003e 'jane@example.com']\n];\n\n$columns = ['id', 'name', 'email'];\n\n$exporter = new Exporter();\n$exporter-\u003ebuild($array, $columns, 'users.csv')\n         -\u003eexport();\n```\n\n#### From PDOStatement (RECOMMENDED)\n```$xslt\n    $servername = \"localhost\";\n    $username = \"root\";\n    $password = \"password\";\n    $dbname = \"laravel\";\n\n    $columns = [\n        'id',\n        'name',\n        'email'\n    ];\n\n    try {\n        $conn = new PDO(\"mysql:host=$servername;dbname=$dbname\", $username, $password);\n        $conn-\u003esetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n        $stmt = $conn-\u003eprepare(\"SELECT id, name, email FROM users\");\n        $stmt-\u003eexecute();\n\n        // set the resulting array to associative\n        $stmt-\u003esetFetchMode(PDO::FETCH_ASSOC);\n\n        $exporter = new Exporter();\n        $exporter-\u003ebuild($stmt, $columns, 'users.csv)\n                 -\u003eexport();\n    }\n    catch(PDOException $e) {\n        echo \"Error: \" . $e-\u003egetMessage();\n    }\n    $conn = null;\n```\n\n## You are always welcome to contribute\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsujancse%2Fphp-csv-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsujancse%2Fphp-csv-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsujancse%2Fphp-csv-exporter/lists"}