andela-aonyango/potato-orm

使用 PHP 和 PDO 构建的轻量级 ORM。

v1.0.3 2016-02-26 12:27 UTC

This package is not auto-updated.

Last update: 2024-09-20 17:52:58 UTC


README

potato-orm

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

一个轻量级的 ORM,允许您向数据库插入记录、检索、更新和删除。

安装

通过 Composer

$ composer require andela-aonyango/potato-orm

在包目录中运行

$ composer install

用法

使用您将要使用的数据库设置编辑此包根目录中提供的示例 .env 文件(确保您在 .gitignore 中忽略 YOUR .env 文件)。给定的示例使用 MYSQL 设置。PDO 支持许多 数据库驱动程序,因此您可以熟悉 DSN 等有效/无效输入。

示例表

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());
?>

变更日志

请参阅 CHANGELOG 了解最近更改的更多信息。

测试

$ composer test

贡献

请参阅 CONTRIBUTINGCONDUCT 了解详细信息。

安全性

如果您发现任何安全相关的问题,请通过电子邮件 andrew.onyango@andela.com 联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。