Skip to content

timefrontiers/php-sql-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TimeFrontiers PHP SQL Database

A flexible SQL database manager supporting MySQLi (default) and PDO with a unified interface.

PHP Version License

Features

  • Backward compatible – drop-in replacement for the legacy MySQLDatabase class.
  • Dual backend support – MySQLi (default) or PDO via factory pattern.
  • Prepared statements – both MySQLiDatabase and PDODatabase support 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.

About

PHP SQL Database connection manager

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages