{"id":15290844,"url":"https://github.com/flightphp/active-record","last_synced_at":"2025-04-13T09:33:00.092Z","repository":{"id":217603709,"uuid":"744329289","full_name":"flightphp/active-record","owner":"flightphp","description":"Micro Active Record library in PHP, supports chain calls, events, and relations.","archived":false,"fork":false,"pushed_at":"2024-07-04T15:41:44.000Z","size":193,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-21T13:51:43.671Z","etag":null,"topics":["active-record","database","flightphp","flipping-sweet","mapper","mysql","orm","query-builder","sqlite"],"latest_commit_sha":null,"homepage":"https://docs.flightphp.com/awesome-plugins/active-record","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bephp/activerecord","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flightphp.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":"2024-01-17T04:24:43.000Z","updated_at":"2024-07-30T05:58:50.595Z","dependencies_parsed_at":"2024-01-22T16:43:53.986Z","dependency_job_id":"a559e458-6cb4-47d9-9ca4-8e6f89036696","html_url":"https://github.com/flightphp/active-record","commit_stats":null,"previous_names":["flightphp/active-record"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Factive-record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Factive-record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Factive-record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightphp%2Factive-record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flightphp","download_url":"https://codeload.github.com/flightphp/active-record/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223581935,"owners_count":17168655,"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":["active-record","database","flightphp","flipping-sweet","mapper","mysql","orm","query-builder","sqlite"],"created_at":"2024-09-30T16:09:43.661Z","updated_at":"2025-04-13T09:33:00.086Z","avatar_url":"https://github.com/flightphp.png","language":"PHP","readme":"# FlightPHP Active Record \n[![Latest Stable Version](https://poser.pugx.org/flightphp/active-record/v)](https://packagist.org/packages/flightphp/active-record)\n[![License](https://poser.pugx.org/flightphp/active-record/license)](https://packagist.org/packages/flightphp/active-record)\n[![PHP Version Require](https://poser.pugx.org/flightphp/active-record/require/php)](https://packagist.org/packages/flightphp/active-record)\n[![Dependencies](https://poser.pugx.org/flightphp/active-record/dependents)](https://packagist.org/packages/flightphp/active-record)\n\nAn active record is mapping a database entity to a PHP object. Spoken plainly, if you have a users table in your database, you can \"translate\" a row in that table to a `User` class and a `$user` object in your codebase. See [basic example](#basic-example).\n\n## Basic Example\n\nLet's assume you have the following table:\n\n```sql\nCREATE TABLE users (\n\tid INTEGER PRIMARY KEY, \n\tname TEXT, \n\tpassword TEXT \n);\n```\n\nNow you can setup a new class to represent this table:\n\n```php\n/**\n * An ActiveRecord class is usually singular\n * \n * It's highly recommended to add the properties of the table as comments here\n *\n * @property int    $id\n * @property string $name\n * @property string $password\n */ \nclass User extends flight\\ActiveRecord {\n\tpublic function __construct($databaseConnection)\n\t{\n\t\tparent::__construct($databaseConnection, 'users', [ /* custom values */ ]);\n\t}\n}\n```\n\nNow watch the magic happen!\n\n```php\n// for sqlite\n$database_connection = new PDO('sqlite:test.db'); // this is just for example, you'd probably use a real database connection\n\n// for mysql\n$database_connection = new PDO('mysql:host=localhost;dbname=test_db\u0026charset=utf8bm4', 'username', 'password');\n\n// or mysqli\n$database_connection = new mysqli('localhost', 'username', 'password', 'test_db');\n// or mysqli with non-object based creation\n$database_connection = mysqli_connect('localhost', 'username', 'password', 'test_db');\n\n$user = new User($database_connection);\n$user-\u003ename = 'Bobby Tables';\n$user-\u003epassword = password_hash('some cool password');\n$user-\u003einsert();\n// or $user-\u003esave();\n\necho $user-\u003eid; // 1\n\n$user-\u003ename = 'Joseph Mamma';\n$user-\u003epassword = password_hash('some cool password again!!!');\n$user-\u003einsert();\n\necho $user-\u003eid; // 2\n```\n\nAnd it was just that easy to add a new user! Now that there is a user row in the database, how do you pull it out?\n\n```php\n$user-\u003efind(1); // find id = 1 in the database and return it.\necho $user-\u003ename; // 'Bobby Tables'\n```\n\nAnd what if you want to find all the users?\n\n```php\n$users = $user-\u003efindAll();\n```\n\nWhat about with a certain condition?\n\n```php\n$users = $user-\u003elike('name', '%mamma%')-\u003efindAll();\n```\n\nSee how much fun this is? Let's install it and get started!\n\n## Installation\n\nSimply install with Composer\n\n```php\ncomposer require flightphp/active-record \n```\n\n## Documentation\n\nHead over to the [documentation page](https://docs.flightphp.com/awesome-plugins/active-record) to learn more about usage and how cool this thing is! :)\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflightphp%2Factive-record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflightphp%2Factive-record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflightphp%2Factive-record/lists"}