{"id":18278279,"url":"https://github.com/erusev/base","last_synced_at":"2025-04-05T16:09:55.302Z","repository":{"id":26310716,"uuid":"29758725","full_name":"erusev/base","owner":"erusev","description":"Simpler Database Intaractions in PHP","archived":false,"fork":false,"pushed_at":"2024-01-05T14:38:07.000Z","size":58,"stargazers_count":262,"open_issues_count":6,"forks_count":16,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-29T15:08:58.273Z","etag":null,"topics":[],"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/erusev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2015-01-23T23:45:12.000Z","updated_at":"2024-10-03T16:01:31.000Z","dependencies_parsed_at":"2024-12-15T07:04:57.618Z","dependency_job_id":"cf4c0a2e-a570-4021-aa18-322416f2f3b6","html_url":"https://github.com/erusev/base","commit_stats":{"total_commits":137,"total_committers":2,"mean_commits":68.5,"dds":0.007299270072992692,"last_synced_commit":"bbd330daabfd825855d6db4cf4caf301a5c916b4"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erusev%2Fbase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erusev%2Fbase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erusev%2Fbase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erusev%2Fbase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erusev","download_url":"https://codeload.github.com/erusev/base/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361693,"owners_count":20926643,"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":[],"created_at":"2024-11-05T12:23:46.618Z","updated_at":"2025-04-05T16:09:55.281Z","avatar_url":"https://github.com/erusev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Base\n\nBase is a simple library that makes it easier to work with databases in PHP. \n\nI have been using it since 2012 and I felt like it is about time I share it.\n\n### Features\n\n- Simple\n- Intuitive\n- Independent\n- Secure\n- Tested in 5.3, 5.4, 5.5, 5.6, 7 and [HHVM](http://hhvm.com/)\n\n### Installation\n\nInclude both `Base.php` and `Collection.php` or install [the composer package](https://packagist.org/packages/erusev/base).\n\n### Examples\n\nConnect to a database:\n```php\n# the constructor takes the same parameters as the PDO constructor\n$Base = new \\Base\\Base('mysql:host=localhost;dbname=example', 'username', 'password');\n```\n\nWork with records:\n```php\n# read user 1\n$Base-\u003ereadItem('user', 1);\n# update the username of user 1\n$Base-\u003eupdateItem('user', 1, ['username' =\u003e 'john.doe']);\n# create a user\n$Base-\u003ecreateItem('user', ['username' =\u003e 'jane.doe', 'email' =\u003e 'jane@example.com']);\n# delete user 1\n$Base-\u003edeleteItem('user', 1);\n```\n\nWork with collections:\n```php\n# read all users\n$Base-\u003efind('user')-\u003eread();\n# read the users that are marked as verified in a desc order\n$Base-\u003efind('user')-\u003ewhereEqual('is_verified', 1)-\u003eorderDesc('id')-\u003eread();\n# read the user with the most reputation\n$Base-\u003efind('user')-\u003elimit(1)-\u003eorderDesc('reputation')-\u003ereadRecord();\n# mark users 1 and 3 as verified\n$Base-\u003efind('user')-\u003ewhereIn('id', [1, 3])-\u003eupdate(['is_verified' =\u003e 1]);\n# count the users that don't have a location\n$Base-\u003efind('user')-\u003ewhereNull('location')-\u003ecount();\n# plain sql conditions are also supported\n$Base-\u003efind('user')-\u003ewhere('is_verified = ?', [1])-\u003eread();\n```\n\nHandle relationships:\n```php\n# read the users that have a featured post\n$Base-\u003efind('user')-\u003ehas('post')-\u003ewhereEqual('post.is_featured', 1)-\u003eread();\n# read the posts of user 1\n$Base-\u003efind('post')-\u003ebelongsTo('user')-\u003ewhereEqual('user.id', 1)-\u003eread();\n# read the posts that are tagged \"php\"\n$Base-\u003efind('post')-\u003ehasAndBelongsTo('tag')-\u003ewhereEqual('tag.name', 'php')-\u003eread();\n# unconventional FK names are also supported\n$Base-\u003efind('user')-\u003ehas('post', 'author_id')-\u003ewhereEqual('user.id', 1)-\u003eread();\n```\n\nExecute queries:\n```php\n# read all users\n$Base-\u003eread('SELECT * FROM user');\n# read user 1\n$Base-\u003ereadRecord('SELECT * FROM user WHERE id = ?', [1]);\n# read the username of user 1\n$Base-\u003ereadField('SELECT username FROM user WHERE id = ?', [1]);\n# read all usernames\n$Base-\u003ereadFields('SELECT username FROM user');\n# update all users\n$Base-\u003eupdate('UPDATE user SET is_verified = ?', [1]);\n```\n\n### Notes\n\n- Not tested on other RDBMSs than MySQL\n- Relationship methods assume that table names are singular - ex: `user` instead of `users`\n- Relationship methods assume that FK names end in `_id` - use `$fkEnding` to customize\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferusev%2Fbase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferusev%2Fbase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferusev%2Fbase/lists"}