{"id":21897248,"url":"https://github.com/h2lsoft/db-manager","last_synced_at":"2025-03-22T05:17:01.304Z","repository":{"id":62513902,"uuid":"257337819","full_name":"h2lsoft/db-manager","owner":"h2lsoft","description":"PDO wrapper to simplify db queries and pagination","archived":false,"fork":false,"pushed_at":"2024-05-28T16:26:34.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-01T08:18:25.353Z","etag":null,"topics":["database","db","mysql","pagination","pdo","pdo-wrapper","php","sql"],"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/h2lsoft.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":"2020-04-20T16:18:42.000Z","updated_at":"2024-05-28T16:01:25.000Z","dependencies_parsed_at":"2024-11-25T11:39:39.623Z","dependency_job_id":"e00499fd-ffe8-491e-b8b0-9e8900f5365f","html_url":"https://github.com/h2lsoft/db-manager","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2lsoft%2Fdb-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2lsoft%2Fdb-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2lsoft%2Fdb-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2lsoft%2Fdb-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2lsoft","download_url":"https://codeload.github.com/h2lsoft/db-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244907463,"owners_count":20529868,"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","db","mysql","pagination","pdo","pdo-wrapper","php","sql"],"created_at":"2024-11-28T14:16:42.234Z","updated_at":"2025-03-22T05:17:01.287Z","avatar_url":"https://github.com/h2lsoft.png","language":"PHP","readme":"# DB Manager\nPDO wrapper to simplify db queries.\nIt provides a simple way to create, retrieve, update \u0026 delete records.\n\n\n[![Version](https://badge.fury.io/gh/h2lsoft%2Fdb-manager.svg)](https://badge.fury.io/gh/h2lsoft%2Fdb-manager)\n\n\n\n## Requirements\n\n- php \u003e= 7.3\n- php PDO extension\n\n\n## Installation\n\nInstall directly via [Composer](https://getcomposer.org):\n```bash\n$ composer require h2lsoft/db-manager\n```\n\n## Basic Usage\n\n```php\nuse \\h2lsoft\\DBManager;\n\n$DBM = new DBManager\\DBManager(); // soft mode is activated by default\n$DBM-\u003econnect('mysql', 'localhost', 'root', '', 'mydatabase');\n\n// execute simple query with binding\n$sql = \"SELECT Name, SurfaceArea FROM Country WHERE Continent = :Continent AND deleted = 'NO' ORDER BY SurfaceArea DESC LIMIT 3\";\n$results = $DBM-\u003equery($sql, [':Continent' =\u003e  'Asia'])-\u003efetchAll();\n\n// or use short version\n$sql = $DBM-\u003eselect(\"Name, SurfaceArea\")\n           -\u003efrom('Country')\n           -\u003ewhere(\"Continent = :Continent\")\n           -\u003eorderBy('SurfaceArea DESC')\n           -\u003elimit(3)\n           -\u003egetSQL();\n$results = $DBM-\u003equery($sql, [':Continent' =\u003e  'Asia'])-\u003efetchAll();\n\n// or imbricated version\n$results = $DBM-\u003eselect(\"Name, SurfaceArea\")\n                      -\u003efrom('Country')\n                      -\u003ewhere(\"Continent = :Continent\")\n                      -\u003eorderBy('SurfaceArea DESC')\n                      -\u003elimit(3)\n                      -\u003eexecuteSql([':Continent' =\u003e  'Asia'])\n                            -\u003efetchAll();\n\n\n// insert\n$values = [];\n$values['Name'] = \"Agatha Christies\";\n$values['Birthdate'] = \"1890-10-15\";\n\n$ID = $DBM-\u003etable('Author')-\u003einsert($values);\n\n\n// update\n$values = [];\n$values['Name'] = \"Agatha Christies\";\n$affected_rows = $DBM-\u003etable('Author')-\u003eupdate($values, $ID); # you can put direct ID or you can use where clause\n\n// delete\n$affected_rows = $DBM-\u003etable('Author')-\u003edelete([\"ID = ?\", $ID]);\n\n\n```\n\n## Soft Mode\n\nSoft mode is activated by default, it allow to automatic timestamp and author on each record for operation like : `Insert`, `Update`, `Delete`.\nSoft mode is optional but recommended, you can disable it in constructor or you can use $DBM-\u003eSoftMode(0);\n\nSoft mode allows you to keep data safe by turn flag field `deleted` to `yes` and no trash your record physically.\nIt is useful to retrieve your data in case of accidentally delete rows.\n\nYou can use magic method `$DBM-\u003etable('my_table')-\u003eaddSoftModeColumns()` this will add automatically soft mode columns :\n\n- `deleted` (enum =\u003e yes, no)\n- `created_at` (datetime)\n- `created_by` (varchar)\n- `updated_at` (datetime)\n- `updated_by` (varchar)\n- `deleted_at` (datetime)\n- `deleted_by` (varchar)\n\n\n## Pagination component\n\n```php\n$sql = $DBM-\u003eselect(\"*\")\n           -\u003efrom('Country')\n           -\u003ewhere(\"Continent = :Continent\")\n           -\u003egetSQL();\n\n$params = [':Continent' =\u003e 'Asia'];\n\n$current_page = 1;\n\n// return a complete array paginate\n$pager = $DBM-\u003epaginate($sql, $params, $current_page, 20);\n```\n\n```\n[\n    [total] =\u003e 51,\n    [per_page] =\u003e 20,\n    [last_page] =\u003e 3,\n    [current_page] =\u003e 1,\n    [from] =\u003e 1,\n    [to] =\u003e 20,\n    [page_start] =\u003e 1,\n    [page_end] =\u003e 3,\n    [data] =\u003e [\n                        ....\n              ]         \n]\n```\n\n## Useful methods\n\n```php\n\n// get a record by ID, you can use multiple ID by array\n$record = $DBM-\u003etable('Country')-\u003egetByID(10);\n\n//  multiple ID\n$records = $DBM-\u003etable('Country')-\u003egetByID([12, 10, 55]);\n\n```\n\n\n\n## License\n\nMIT. See full [license](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2lsoft%2Fdb-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2lsoft%2Fdb-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2lsoft%2Fdb-manager/lists"}