A light-weight ORM which allows you to insert records into a database, retrieve them, update them, and delete them.
Via Composer
$ composer require andela-aonyango/potato-orm
In the package directory, run
$ composer install
Edit the example .env provided in the root of this package with the database settings you will use (make sure you .gitignore YOUR .env file). The one given uses MYSQL settings. PDO supports many database drivers so you can get familiar with what are valid/invalid inputs for the DSN and so on.
create table Person (
id int unsigned auto_increment primary key,
first_name varchar(30) not null,
last_name varchar(30) not null,
age int(2),
gender varchar(7)
);
<?php
// Example usage of this ORM
require "vendor/autoload.php";
use PotatoORM\Models\Person;
$person = new Person();
$person->first_name = "yua";
$person->last_name = "madha";
$person->age = 73;
// the add() method inserts an object and returns the last inserted id
$id = $person->add();
// retrieve the just-added person
$test = $person->find($id);
print_r($test);
$test->gender = "female";
$test->update();
// is the update successful
print_r($test->find($id));
// delete the person from the database
$test->remove();
// retrieve all people
print_r($person->findAll());
?>
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email andrew.onyango@andela.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.