thomas-squall/efxphp
Composer 安装命令:
composer require thomas-squall/efxphp
包简介
MySQL Entity Framework for PHP
README 文档
README
This is an Entity Framework for PHP based on MySQL.
Installation
Using composer is quite simple, just run the following command:
$ composer require thomas-squall/efxphp
Prerequisites
Before using this library you should make sure to have installed PHP7.1 or major.
Usage
At first, you need to connect to the database.
The parameter to pass are:
- $host = The URL to the server where the database is running (localhost for local databases)
- $username = The username to login into MySQL
- $password = The password to login into MySQL
- $database = The database name to connect to
For more information see the link: https://docs.mongodb.com/manual/reference/connection-string/
This is how you instantiate a new Adapter:
use EFxPHP\Adapter; // Enstablish a connection. $adapter = new Adapter(); $adapter->connect($host, $username, $password, $database);
Now you have to create a model
/** * @Model(name = "people") */ class person { /** * @Type(type = "varchar", length = 16) * @var string $name */ public $name; /** * @Type(type = "int") * @var int $age */ public $age; /** * @Type(type = "varchar", length = 10) * @Default(value = "italian") * @var string $nationality */ public $nationality; }
And register it
$db->registerModel(new person());
If you want to create/update your tables automatically based on your model, pass true as second parameter in the registerModel method
/* * Note that this will: * 1. Create the table if it does not exist * 2. Add new columns if you added new parameters to the model * 3. Remove unused columns if you deleted parameters from the model * * Specially for point 3, use it with care. */ $db->registerModel(new person(), true);
Find
Once connected to the database we can simply query for the collection we want:
$items = $adapter->find('people');
You can also filter your query:
use MongDriver\Filter; $filters = [ new Filter('age', 29, Filter::IS_EQUALS), new Filter('nationality', ['italian', 'spanish'], Filters::IS_IN_ARRAY) ]; $items = $adapter->find('people', $filters);
Insert
If you want to insert an item you have simply to pass an instance of a registered model:
$item = new Person(); $item->name = 'Thomas'; $item->surname = 'Cocchiara'); $adapter->insert($item);
Hope you guys find this library useful.
Please share it and give me a feedback :)
Thomas
thomas-squall/efxphp 适用场景与选型建议
thomas-squall/efxphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 thomas-squall/efxphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thomas-squall/efxphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-08