{"id":15029011,"url":"https://github.com/anthonygauthier/mysimpleorm","last_synced_at":"2025-04-09T20:32:36.723Z","repository":{"id":57022882,"uuid":"89405490","full_name":"anthonygauthier/MySimpleORM","owner":"anthonygauthier","description":"Simple, lightweight and effective PHP ORM using MySQLi.","archived":false,"fork":false,"pushed_at":"2020-02-21T16:02:28.000Z","size":87,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T22:26:08.741Z","etag":null,"topics":["crud","database","database-abstraction","json","library","mysql","mysqli","object","object-detection","object-mapper","object-mapping","object-oriented","object-relational","object-relational-mapper","orm","orm-php-framework","php","php5","php7","sqlobject"],"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/anthonygauthier.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}},"created_at":"2017-04-25T20:49:30.000Z","updated_at":"2023-06-14T04:27:47.000Z","dependencies_parsed_at":"2022-08-23T13:50:19.576Z","dependency_job_id":null,"html_url":"https://github.com/anthonygauthier/MySimpleORM","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonygauthier%2FMySimpleORM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonygauthier%2FMySimpleORM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonygauthier%2FMySimpleORM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anthonygauthier%2FMySimpleORM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anthonygauthier","download_url":"https://codeload.github.com/anthonygauthier/MySimpleORM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107638,"owners_count":21048971,"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":["crud","database","database-abstraction","json","library","mysql","mysqli","object","object-detection","object-mapper","object-mapping","object-oriented","object-relational","object-relational-mapper","orm","orm-php-framework","php","php5","php7","sqlobject"],"created_at":"2024-09-24T20:09:32.512Z","updated_at":"2025-04-09T20:32:36.693Z","avatar_url":"https://github.com/anthonygauthier.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MySimpleORM\nMySimpleORM is a simple PHP/MySQL Object-relational mapping library. It is lightweight and tries to take care of as many things as possible. It allows you to focus on coding the business logic of your application without having to think too much about the SQL queries, simply write your conditions and the ORM will take care of the rest :smile: !\n\n## Setting up MySimpleORM (MsORM)\nTo be able to use the ORM, you need to have a PHP application and a MySQL/MariaDB database. Follow these simple guidelines to setup MsORM within your PHP web app.\n\n## Installation\nThe recommended method of installation is via [composer](https://getcomposer.org/)\n\n`composer require mysimpleorm/mysimpleorm`\n\n### Database-side guidelines\n1. The name of your tables are going to be the names of your object classes in PHP. Therefore, a table named \"Users\" will refer to the class \"Users\".\n\n\n### Setup\n\nAdd the following to your PHP class:\n\n1. `require 'vendor/autoload.php;`\n2. `use MySimpleORM\\BaseClass;`\n3. `extends BaseClass`\n4. Change your `private` class attributes to `protected` to give access to the mapper.\n5. Setup your MySQL/MariaDB information (check the example below)\n\nNo need for getters/setters, the `BaseClass` provides you a generic methods.\n\n#### Example\n\n```php\nrequire 'vendor/autoload.php';\n\nuse MySimpleORM\\BaseClass;\n\nclass MyClass extends BaseClass {\n  protected $IDMyClass;\n  protected $Name;\n\n  public function MyClass() {\n    parent::__construct($this);\n    /**\n    * There are two ways to connect the ORM to your Database.\n    *\n    * 1. Set the following environment variables:\n    *    - DB_HOSTNAME\n    *    - DB_USERNAME\n    *    - DB_PASSWORD\n    *    - DB_DATABASE\n    *    - DB_PORT\n    *\n    * 2. Call the following method\n    *    - $this-\u003eMapper-\u003eDatabase-\u003esetup($host, $user, $password, $db, $port);\n    */\n    $this-\u003eIDMyClass = 0;\n    $this-\u003eName = \"\";\n  }\n  public function __destruct() {}\n}\n```\n\n#### Example of a table\n| _MyClass_ |\n|-----------|\n| IDMyClass |\n| Name      |\n\n## Documentation\n*The examples below are all used as if they were part of a function within a controller (MVC).\n\n### Generic get/set\nThe ORM provides generic get \u0026 set methods to help alleviate the content of your class.\n\n#### Get\n```php\n$Users = new Users();\n$name = $Users-\u003eget('Name');\n// $class-\u003eget(attribute_name) =\u003e returns value of the attribute\n```\n#### Set\n```php\n$Users = new Users();\n$name = $Users-\u003eset('Name', 'foo');\n// $class-\u003eset(attribute_name, value) =\u003e sets the attribute to the value\n```\n\n### Select\n#### To select an object by its ID\n```php\n$Users = new Users();\n$Users = $Users-\u003efindById(1);\n```\nYou've retrieved the user \"1\" from the table \"Users\" and can now use it as an object.\n\n#### To retrieve an array of objects\n```php\n\n$Users = new Users();\n//replace by whatever condition you desire\n$wheres = array(\n    \"column\" =\u003e \"IDCompanies\",\n    \"condition\" =\u003e \"=\",\n    \"value\" =\u003e 1 //keep in mind you could use a sub-query here\n);\n// OR\n$wheres = array(\n\"IDCompanies,=,1\"\n)\n$Users = $Users-\u003egetArray($wheres);\n```\nYou've just retrieved all the users that were part of the company \"1\". You're object ```$Users``` is now an array of ```Users```\n\n#### To retrieve current object, depending on what you've already set\nAssuming the database contains a```Users``` with the name \"foo\".\n```php\n\n$Users = new Users();\n$Users-\u003eset(\"Name\", \"foo\");\n$Users = $Users-\u003egetCurrent();\n\n//The mapper returned the object User named \"foo\"\n``` \n\n### Insert / Update / Delete\nInserting, updating or deleting an object is very simple. All you need to do is call a few functions!\n```php\n//Insert \u0026 Update\n$Users = new $Users();\n$Users-\u003eset(\"Name\", \"foo\");\n$Users-\u003esave(); // inserted\n\n$Users-\u003eset(\"Name\", \"bar\");\n$Users-\u003esave(); // updated\n\n//Delete\n$Users-\u003edelete();\n// $Users is now undefined\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonygauthier%2Fmysimpleorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanthonygauthier%2Fmysimpleorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanthonygauthier%2Fmysimpleorm/lists"}