robertasproniu/php-simple-db-orm
Composer 安装命令:
composer require robertasproniu/php-simple-db-orm
包简介
A PHP database manager with simple ORM attached
README 文档
README
Installation
Use Composer
"require" : { "robertasproniu/php-simple-db-orm": "~1.0" }
Initialize
require_once 'vendor/autoload.php'; use SimpleDataBaseOrm\Database; use SimpleDataBaseOrm\DatabaseConnection; use SimpleDataBaseOrm\DatabaseConfiguration; $configuration = [ 'default' => 'default', 'connections' => [ 'default' => [ 'driver' => 'mysql', 'hostname' => 'database_hostname', 'username' => 'database_username', 'password' => 'database_password', 'database' => 'database_name' ], // optional can have multiple databases 'remote' => [ 'driver' => 'mysql', 'hostname' => 'database_hostname', 'username' => 'database_username', 'password' => 'database_password', 'database' => 'database_name' ] ] ] $dbConfiguration = new DatabaseConfiguration($configuration); // OR $dbConfiguration = new DatabaseConfiguration("path/to/database_cfg.php"); "path/to/database_cfg.php" should return an array $database = new Database(new DatabaseConnection, $dbConfiguration);
Usage
Examples selecting, inserting, updating and deleting data from or into products table.
// SELECT * FROM `products` WHERE `price` = ? $results = $database->select() ->from('products') ->where('price', 99) ->execute(); print_r($results); // [] of results (associative arrays); // INSERT INTO `products` ( `name` , `price` ) VALUES ( ? , ? ) $results = $database->insert(['name', 'price']) ->into('products') ->values([ 'ProductName', 199 ]) ->execute(); print_r($results); // [ 'id' => {{ insertedId }} ] OR []; // UPDATE `products` SET `price` = ? WHERE `id` = ? $results = $database->update([ 'price' => 199)) ->table('products') ->where('id', 1) ->execute(); print_r($results); // [ 'rows' => {{ numberOfAffectedRows }} ] OR []; // DELETE FROM `products` WHERE `id` = ? $results = $database->delete() ->from('products') ->where('id', 1) ->execute(); print_r($results); // [ 'rows' => {{ numberOfAffectedRows }} ] OR [];
Using Transaction
$database->transaction(function() use ($database) { // multiple queries $database->insert(['name', 'price']) ->into('products') ->values([ 'ProductName', 199 ]) ->execute(); $database->update([ 'price' => 199)) ->table('products') ->where('id', 1) ->execute(); }); //OR $database->transaction(function($database){ $database->delete() ->from('products') ->where('id', 1) ->execute(); });
Switching between database connections
$database->connection('remote');
robertasproniu/php-simple-db-orm 适用场景与选型建议
robertasproniu/php-simple-db-orm 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 robertasproniu/php-simple-db-orm 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robertasproniu/php-simple-db-orm 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-15