{"id":25866362,"url":"https://github.com/antevenio/pdo-mysql-select-iterator","last_synced_at":"2025-03-02T02:30:12.799Z","repository":{"id":56948782,"uuid":"82830758","full_name":"Antevenio/pdo-mysql-select-iterator","owner":"Antevenio","description":"PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses","archived":false,"fork":false,"pushed_at":"2024-12-02T11:03:30.000Z","size":77,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-04T14:25:53.127Z","etag":null,"topics":["iterator","limit","mysql","pdo","php","select"],"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/Antevenio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-22T17:05:23.000Z","updated_at":"2023-04-18T14:59:32.000Z","dependencies_parsed_at":"2024-08-12T10:26:50.757Z","dependency_job_id":"a5c5b6a0-51c1-475d-9975-6282965a63c0","html_url":"https://github.com/Antevenio/pdo-mysql-select-iterator","commit_stats":{"total_commits":54,"total_committers":2,"mean_commits":27.0,"dds":0.4814814814814815,"last_synced_commit":"e57c4278ae5ac10da309712648d6390c0deb10b8"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antevenio%2Fpdo-mysql-select-iterator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antevenio%2Fpdo-mysql-select-iterator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antevenio%2Fpdo-mysql-select-iterator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antevenio%2Fpdo-mysql-select-iterator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antevenio","download_url":"https://codeload.github.com/Antevenio/pdo-mysql-select-iterator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241448611,"owners_count":19964475,"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","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":["iterator","limit","mysql","pdo","php","select"],"created_at":"2025-03-02T02:30:11.759Z","updated_at":"2025-03-02T02:30:12.740Z","avatar_url":"https://github.com/Antevenio.png","language":"PHP","readme":"# pdo-mysql-select-iterator\n[![Latest Stable Version](https://poser.pugx.org/antevenio/pdo-mysql-select-iterator/v/stable)](https://packagist.org/packages/antevenio/pdo-mysql-select-iterator)\n[![Total Downloads](https://poser.pugx.org/antevenio/pdo-mysql-select-iterator/downloads)](https://packagist.org/packages/antevenio/pdo-mysql-select-iterator)\n[![License](https://poser.pugx.org/antevenio/pdo-mysql-select-iterator/license)](https://packagist.org/packages/antevenio/pdo-mysql-select-iterator)\n[![Build Status](https://travis-ci.org/Antevenio/pdo-mysql-select-iterator.svg?branch=master)](https://travis-ci.org/Antevenio/pdo-mysql-select-iterator)\n[![Code Climate](https://codeclimate.com/github/Antevenio/pdo-mysql-select-iterator.png)](https://codeclimate.com/github/Antevenio/pdo-mysql-select-iterator)\n\nPHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses.\n\nWhat is this thing\n---\nSo, you want to iterate through millions of table rows coming as a result\nof some MySQL select query because you want to do your thingie with them, but alas!, your lovely\ndatabase admin doesn't like queries that stay for too long running in his server,\nor even worse, the server itself isn't able to hold them!. What do we do?, we do issue several\nqueries that would fetch smaller blocks of rows in place.\n\n\nThis is an just a PHP iterator based on this concept. Upon receiving a SELECT query and a\nPDO database connection, an iterator is built so you can seamlessly traverse results without\nhaving to worry about anything else.\n\nInstall\n---\n\nTo add as a dependency using composer:\n\n`composer require antevenio/pdo-mysql-select-iterator`\n\nUsage example\n---\n\n```php\n\u003c?php\n$pdo = new PDO('mysql:host=localhost;dbname=kidsshouting', 'myuser', 'mypass');\n$iterator = (new \\PdoMysqlSelectIterator\\Factory())\n    -\u003ecreate($pdo, \"select a,b from tbl order by a\", 1000);\n// Get a total row count from the query if needed\n$total = count($iterator);\nforeach ($iterator as $item) {\n    // Do your stuff with $item\n}\n```\n\nNotes\n---\nThe factory will throw a InvalidQueryException on non \"select\" queries.\n\nThe factory will only return a LimitIterator when:\n* The blockSize is \u003e 0\n* The query has an \"order by\" clause\n* The query is not using any \"rand()\" functions\n\nIf any of the previous conditions is NOT met, the factory will return a non limit based iterator called \n\"NativePDOIterator\". \n\nTo ensure consistency among results, you might want to get the whole iteration and count inside a database transaction.\nThe most suitable isolation level would be REPEATABLE-READ: \n\nhttps://dev.mysql.com/doc/refman/5.7/en/innodb-transaction-isolation-levels.html#isolevel_repeatable-read\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantevenio%2Fpdo-mysql-select-iterator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantevenio%2Fpdo-mysql-select-iterator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantevenio%2Fpdo-mysql-select-iterator/lists"}