leven-framework/dba-common
Composer 安装命令:
composer require leven-framework/dba-common
包简介
README 文档
README
Features
- 🧪 abstract access to the database
- 🏗 simple query builder with nested conditions support
- 🔐 automatic escaping of table and column names and values
Usage examples
Select
$result = $db->select('foo_table') ->columns('id', 'name') // optional, defaults to all columns ->where('id', '>', 1)->orWhere('age', '>', 22) ->orWhere(fn(\Leven\DBA\Common\BuilderPart\WhereGroup $w) => $w ->where('name', 'IN', ['Foo', 'Bar']) ->andWhere('description', 'LIKE', '%foo%') ) ->orderDesc('id')->orderAsc('name') ->limit(1)->offset(1) ->execute(); foreach($result as $row) {} // you can iterate over the rows $result->rows; // or access the rows as an array $result->count; // count of rows returned
Insert
$result = $db->insert('foo_table', ['name' => 'Foo']); $result->lastId; // last inserted id (auto increment) or null
Update
$db->update('foo_table') ->set('name', 'Foo') ->where('id', '!=', 3) ->limit(10) ->execute();
Delete
$db->delete('foo_table') ->where('id', 5) ->limit(11) ->execute();
Implementations
📦 MySQL
composer require leven-framework/dba-mysql
require 'vendor/autoload.php'; // all arguments are optional except for database $db = new \Leven\DBA\MySQL\MySQLAdapter( database: 'example', user: 'username', password: 'password', host: 'localhost', port: 3306, charset: 'utf8', tablePrefix: 'prefix_' ); // or use an existing PDO instance $db = new \Leven\DBA\MySQL\MySQLAdapter($pdo);
📦 Mock
composer require leven-framework/dba-mock
require 'vendor/autoload.php'; // saving and loading the database in JSON is slow but useful for development $db = new \Leven\DBA\Mock\MockAdapter( fn() => json_decode(file_get_contents('db.json'), true), fn(\Leven\DBA\Mock\Structure\Database $db) => file_put_contents('db.json', json_encode($db->toArray(), JSON_PRETTY_PRINT)) ); // first argument can also be an array representing the database $dbArray = [ 'foo_table' => [ ['id' => 'int', 'name' => 'varchar'], [1, 'Foo'], [2, 'Bar'], ], ];
leven-framework/dba-common 适用场景与选型建议
leven-framework/dba-common 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 02 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 leven-framework/dba-common 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 leven-framework/dba-common 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2022-02-19