定制 wcatron/mysql-db-framework 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wcatron/mysql-db-framework

Composer 安装命令:

composer require wcatron/mysql-db-framework

包简介

A MySQL ODM (assistant) extremely flexible for any project.

README 文档

README

A MySQL ODM (assistant) extremely flexible for any project.

Build Status

Overview

This framework allows you to quickly map objects to rows in a MySQL database.

Setup

Create models for your objects and have them extend Row. Implement the toRow and fromRow methods and set the TABLE and ID_COLUMN constants. Call MyDB::configure() in your autoload.php file or wherever needed before database calls. You can now perform queries and get php objects back.

Installation

Composer

composer require wcatron/mysql-db-framework

Models & MDB

Models

Your classes. Add two functions and two constants and allow any model to create objects.

class Your Class extends Row {
    /** @var LinkedObject */
    var $linkedObject;

    const TABLE = "table";
    const ID_COLUMN = "table_id";

    function __construct() {
        $this->setObjectForKey(LinkedObjectClass::class, 'linked_id', 'linkedObject');
    }

    function toRow() {
        $row = parent::toRow();
        // ... Add your fields to the row.
        return $row;
    }

    function fromRow($row) {
        parent::fromRow($row);
        // ... Set your fields.
    }
}

Saving is extremely simple when you have an object whose class extends row.

$object->save();

MyDB

Your connection to mysql. To get your rows as objects use this singleton MyDB::getInstance()

getObjectByID(Class::class,$id)

Alternatively you can just call getByID($id) on your custom Row object.

This will return your exact object.

getObjectsWithQuery(Class::class,$query)

An array of objects based on a custom query. Not all queries need to be written out though.

getObjectByColumn(Class::class, 'ColumnName', $value)

If you're only searching by one column use this simple function.

统计信息

  • 总下载量: 109
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固