{"id":20678880,"url":"https://github.com/phpgt/database","last_synced_at":"2025-07-25T02:03:10.444Z","repository":{"id":4240570,"uuid":"52398644","full_name":"phpgt/Database","owner":"phpgt","description":"Database query organisation.","archived":false,"fork":false,"pushed_at":"2025-05-19T10:13:01.000Z","size":775,"stargazers_count":3,"open_issues_count":21,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T15:59:06.007Z","etag":null,"topics":["database","database-access","database-api-organisation","database-logic-organisation","database-migrations","php-library","php-pdo","phpgt","sql","sql-database","sql-query"],"latest_commit_sha":null,"homepage":"https://php.gt/database","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/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":["phpgt"]}},"created_at":"2016-02-23T23:13:39.000Z","updated_at":"2025-05-19T10:13:04.000Z","dependencies_parsed_at":"2023-10-11T17:17:39.394Z","dependency_job_id":"e2b24ce6-eefe-413c-b28b-216021f5afdb","html_url":"https://github.com/phpgt/Database","commit_stats":{"total_commits":442,"total_committers":9,"mean_commits":"49.111111111111114","dds":"0.11085972850678738","last_synced_commit":"952a876a993f7f06ee0c6bbddc6083af73a2bfb2"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/phpgt/Database","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/Database/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FDatabase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264614358,"owners_count":23637568,"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":["database","database-access","database-api-organisation","database-logic-organisation","database-migrations","php-library","php-pdo","phpgt","sql","sql-database","sql-query"],"created_at":"2024-11-16T21:22:53.692Z","updated_at":"2025-07-10T17:05:09.729Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","readme":"\u003cimg src=\"logo.png\" alt=\"Database logic organisation.\" align=\"right\" /\u003e\n\n# Database API organisation.\n\nEncloses your application's database scripts within a simple and standardised interface, separating database access from your application logic.\n\nThe first parameter to any database functions is always the query name, which represents a query file on disk - either a raw SQL file or a PHP representation of a query using [SqlBuilder][sqlbuilder].\n\n***\n\n\u003ca href=\"https://github.com/PhpGt/Database/actions\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/database-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codacy.com/gh/PhpGt/Database\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/database-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/PhpGt/Database\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/database-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/Database\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/database-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"http://www.php.gt/database\" target=\"_blank\"\u003e\n\t\u003cimg src=\"https://badge.status.php.gt/database-docs.svg\" alt=\"PHP.Gt/Database documentation\" /\u003e\n\u003c/a\u003e\n\n## Example usage\n\nThis library organises SQL access through a consistent API. To execute an example query located at `src/query/user/getById.sql`, the following pattern is used:\n\n```php\n$userRow = $db-\u003efetch(\"user/getById\", 105);\n```\n\nExamples of CRUD operations:\n\n```php\n// \"fetchAll\" method returns an iterable ResultSet of Row objects.\n$bookResultSet = $db-\u003efetchAll(\"shopitem/getItemsInCategory\", \"books\");\n\nforeach($bookResultSet as $bookRow) {\n\techo \"Book title: \", $bookRow-\u003egetString(\"title\"), PHP_EOL;\n\techo \"Book price: £\", ($bookRow-\u003egetFloat(\"price\") + $bookRow-\u003egetFloat(\"vat\")), PHP_EOL;\n\t\n\tif($bookRow-\u003eofferEnds) {\n\t\techo \"Item on offer until: \", $bookRow-\u003egetDateTime(\"offerEnds\")-\u003eformat(\"dS M Y\");\n\t}\n}\n\n// \"Create\" method always returns the last inserted ID:\n$newCustomerId = $db-\u003ecreate(\"customer/new\", [\n\t\"first_name\" =\u003e \"Marissa\",\n\t\"last_name\" =\u003e \"Mayer\",\n\t\"dob\" =\u003e new DateTime(\"1975-05-30\"),\n]);\n\n// \"Update\" or \"delete\" methods always return the number of affected rows:\n$numberOfItemsAffected = $db-\u003eupdate(\"shop/item/increasePrice\", [\n\t\"percent\" =\u003e 12.5,\n\t\"max_increase\" =\u003e 20.00,\n]);\n\n$numberOfDeletedReviews = $db-\u003edelete(\n\t\"remove/deleteOlderThan\",\n\tnew DateTime(\"-6 months\")\n);\n\n// Individual type-safe fields can be pulled from queries that return only one column:\n$userName = $db-\u003efetchString(\"user/getUsernameById\", 105);\n```\n\n## Features at a glance\n\n+ [Automatic database migrations][wiki-migrations]\n+ [Encapsulation of queries using `QueryCollection`s][wiki-query-collections]\n+ [Bind parameters by name or sequentially][wiki-parameters]\n+ [Fully configurable][wiki-config]\n+ [Type safe getters][wiki-type-safety]\n\n[sqlbuilder]: https://www.php.gt/sqlbuilder\n[wiki-query-collections]: https://www.php.gt/docs/database/query-collections\n[wiki-parameters]: https://www.php.gt/docs/database/parameters\n[wiki-migrations]: https://www.php.gt/docs/database/migrations\n[wiki-config]: https://www.php.gt/docs/database/config\n[wiki-type-safety]: https://www.php.gt/docs/database/type-safety\n","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fdatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Fdatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Fdatabase/lists"}