fomadev / bridgesql
Universal PDO library supporting 10 DBMS.
Requires
- php: >=8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2026-05-13 07:02:32 UTC
README
BridgeSQL is a lightweight, universal PHP library designed to simplify the use of PDO. It acts as a robust bridge between your code and 10 different database management systems (DBMS), automating connection configuration, data type management, and query debugging.
Features
- Multi-DBMS Support: A single interface for 10 SQL engines (MySQL, PostgreSQL, SQLite, Oracle, SQL Server, etc.).
- Auto-Typing: Automatic detection of PDO types (Integer, Boolean, String, Null) via PHP 8
match. - Parameter Flexibility: Supports named (
:id) and indexed (?) parameters. - Security: Systematic use of prepared statements with emulation disabled for maximum security.
- Logging & Debugging: Track execution time and view interpolated SQL queries for easier debugging.
- Lightweight: No external dependencies required for basic operation.
Installation
Use Composer to install the library:
composer require fomadev/bridgesql
Supported DBMS
BridgeSQL facilitates connection to the following systems:
-
MySQL & MariaDB
-
PostgreSQL
-
SQLite (Local file or
:memory:) -
Microsoft SQL Server (MSSQL)
-
Oracle (OCI)
-
IBM DB2
-
Firebird
-
Informix
-
Sybase (SAP ASE)
Quick Use
Configuration
Create a configuration file (e.g., config/database.php):
return [ 'driver' => 'mysql', 'host' => 'localhost', 'dbname' => 'my_database', 'username' => 'root', 'password' => '', 'charset' => 'utf8mb4' ];
Query Execution & Debugging
require 'vendor/autoload.php'; use BridgeSQL\BridgeSQL; $config = require 'config/database.php'; $db = new BridgeSQL($config); // Retrieve a single line $user = $db->fetch("SELECT * FROM users WHERE id = :id", ['id' => 1]); // Insert data with auto-typing $db->execute("INSERT INTO users (name, active) VALUES (?, ?)", ["Molengo", true]); // --- Debugging Features (New in v2.0.1) --- // Get the last executed query with parameters injected echo $db->getLastQuery(); // Output: INSERT INTO users (name, active) VALUES ('Molengo', 1) // Get full session logs (SQL, duration, and timestamp) $logs = $db->getDebugLog(); print_r($logs);
Transactions
$db->beginTransaction(); try { $db->execute("UPDATE accounts SET balance = balance - 100 WHERE id = 1"); $db->execute("UPDATE accounts SET balance = balance + 100 WHERE id = 2"); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; }
Contributing
Please see CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
License
This project is licensed under the FomaDev Public License (FPL).
- Free for use as a dependency in personal and commercial projects.
- Paid license required for redistribution, derivative libraries, or competing commercial services.
See the LICENSE file for the full text.