timefrontiers/php-sql-database
最新稳定版本:v1.0.3
Composer 安装命令:
composer require timefrontiers/php-sql-database
包简介
PHP SQL Database manager supporting MySQLi and PDO with backward compatibility
README 文档
README
A flexible SQL database manager supporting MySQLi (default) and PDO with a unified interface.
Features
- Backward compatible – drop-in replacement for the legacy
MySQLDatabaseclass. - Dual backend support – MySQLi (default) or PDO via factory pattern.
- Prepared statements – both
MySQLiDatabaseandPDODatabasesupport secure parameterized queries. - Unified API – same method names across both drivers.
- Error collection – consistent with other TimeFrontiers packages.
Installation
composer require timefrontiers/php-sql-database
Requirements
- PHP 8.1 or higher
ext-mysqli(always required)ext-pdo+ driver (optional, for PDO support)
Basic Usage
Default: MySQLiDatabase
use TimeFrontiers\SQLDatabase; // This uses MySQLiDatabase internally (backward compatible) $db = new SQLDatabase('localhost', 'root', 'secret', 'my_database');
Using PDO Instead
use TimeFrontiers\SQLDatabase; use TimeFrontiers\PDODatabase; // Pass the PDO class name as the fourth parameter $db = new SQLDatabase('localhost', 'root', 'secret', PDODatabase::class, driver: 'mysql');
Executing Queries (Legacy Style)
$result = $db->query("SELECT * FROM users WHERE id = 1"); while ($row = $db->fetchAssocArray($result)) { // ... }
Using Prepared Statements (Recommended)
// Fetch all rows $users = $db->fetchAll("SELECT * FROM users WHERE status = ?", ['active']); // Fetch single row $user = $db->fetchOne("SELECT * FROM users WHERE id = ?", [5]); // Execute INSERT/UPDATE $db->execute("UPDATE users SET name = ? WHERE id = ?", ['John', 5]); $newId = $db->insertId();
License
MIT License. See LICENSE for details.
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-14