victorvolpe/php-pdo-wrapper
Composer 安装命令:
composer require victorvolpe/php-pdo-wrapper
包简介
A modern PDO wrapper for PHP 8.2+, supporting dynamic placeholders and secure database access.
README 文档
README
A simple, modern, and lightweight PHP PDO wrapper for MySQL (and compatible databases). Built with type safety, PSR standards, and inspired by lincanbin/PHP-PDO-MySQL-Class.
Features
- Easy database connections with automatic retry
- Secure query binding (including
IN (?)arrays support) - Fluent methods for common operations (select, insert, update, delete)
- Transaction support
- Error handling with automatic reconnection on server timeout
- Simple logging for connection and query errors
Installation
You can install via Composer:
composer require victorvolpe/php-pdo-wrapper
Or simply include DB.php manually if you prefer not to use Composer.
Usage
1. Instantiate the Database
use VictorVolpe\PhpPdoWrapper\DB; $db = new DB( dsn: 'mysql:host=localhost;dbname=testdb;charset=utf8mb4', user: 'your_username', pass: 'your_password' );
2. Basic Query
$users = $db->query("SELECT * FROM users WHERE status = :status", [ 'status' => 'active' ]);
3. Fetch a Single Row
$user = $db->row("SELECT * FROM users WHERE id = :id", [ 'id' => 1 ]);
4. Fetch a Single Column
$emails = $db->column("SELECT email FROM users WHERE status = :status", [ 'status' => 'active' ]);
5. Fetch a Single Value
$email = $db->single("SELECT email FROM users WHERE id = :id", [ 'id' => 1 ]);
6. Insert a New Record
$newUserId = $db->insert('users', [ 'username' => 'newuser', 'email' => 'newuser@example.com', 'status' => 'active' ]);
7. Update Existing Records
$rowsAffected = $db->update('users', [ 'status' => 'inactive' ], "last_login < :date", [ 'date' => '2024-01-01' ]);
8. Delete Records
$rowsDeleted = $db->delete('users', "status = :status", [ 'status' => 'inactive' ]);
9. Transactions
$db->begin(); try { $db->query("UPDATE accounts SET balance = balance - :amount WHERE id = :id", [ 'amount' => 100, 'id' => 1 ]); $db->query("UPDATE accounts SET balance = balance + :amount WHERE id = :id", [ 'amount' => 100, 'id' => 2 ]); $db->commit(); } catch (Exception $e) { $db->rollback(); throw $e; }
Logging
If a connection error or query exception occurs, a log file will automatically be created in:
/logs/db-YYYY-MM-DD.log
License
This project is open-sourced under the MIT License.
victorvolpe/php-pdo-wrapper 适用场景与选型建议
victorvolpe/php-pdo-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「php」 「db」 「mysql」 「pdo」 「wrapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 victorvolpe/php-pdo-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 victorvolpe/php-pdo-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 victorvolpe/php-pdo-wrapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
VV database abstraction layer with query builder and DB structure models
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-27