php-orm is a micro-library built with PHP7 and PDO that simplify daily work with MySQL database.
If composer
is not installed on your system yet, you may go ahead and install it using this command line:
$ curl -sS https://getcomposer.org/installer | php
Next, add the following require entry to the composer.json
file in the root of your project.
"require" : { "riverside/php-orm" : "*" }
Finally, use composer
to install php-orm and its dependencies:
$ php composer.phar install
php-orm expects the following environment variables at local level:
<?php $_ENV['PHP_ORM_DSN'] = 'mysql:host=localhost;dbname=mydb'; $_ENV['PHP_ORM_USER'] = 'myuser'; $_ENV['PHP_ORM_PSWD'] = 'mypswd';
Include autoload in your project:
<?php require __DIR__ . '/vendor/autoload.php';
<?php use PhpOrm\DB; class User extends DB { protected $table = 'users'; protected $attributes = ['id', 'name', 'email']; public static function factory() { return new self(); } }
To add a row use the insert()
method.
User::factory() ->insert(['name' => 'John']);
To read a row by it's id
column use the find()
method.
User::factory()->find(1);
To get multiple records use the get()
method.
User::factory()->get();
To get the first record use the first()
method.
User::factory()->first();
To edit a row use the update()
method.
User::factory() ->where('id', '=', 1) ->update(['name' => 'John Smith']);
To delete a row use the delete()
method.
User::factory() ->where('id', '=', 1) ->delete();
The project is hosted on GitHub.
php-orm is licensed under the MIT license.
If you like the php-orm please share this link with your friends and colleagues.
Join our mailing list and stay tuned! Never miss out news about Zino UI, new releases, or even blog post.
Comments are closed