A flexible SQL database manager supporting MySQLi (default) and PDO with a unified interface.
- 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.
composer require timefrontiers/php-sql-database- PHP 8.1 or higher
ext-mysqli(always required)ext-pdo+ driver (optional, for PDO support)
use TimeFrontiers\SQLDatabase;
// This uses MySQLiDatabase internally (backward compatible)
$db = new SQLDatabase('localhost', 'root', 'secret', 'my_database');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');$result = $db->query("SELECT * FROM users WHERE id = 1");
while ($row = $db->fetchAssocArray($result)) {
// ...
}// 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();MIT License. See LICENSE for details.