Production-grade, single-file PDO execution core and lightweight query builder for PHP.
Provides a secure, ergonomic, and efficient way to interact with databases using prepared statements, strict validation, and zero-dependency architecture.
Based on long-term production backend design principles.
This project is designed using Principal / Lead Architect backend standards:
✅ Security First
✅ Prepared Statements Only
✅ Deterministic Query Execution
✅ Zero Framework Lock-In
✅ Zero Runtime Dependencies
✅ Long-Term Maintainability (10+ years mindset)
✅ Production Infrastructure Friendly
Drop into any project instantly.
No Composer required.
No dependency hell.
Supports:
- MySQL / MariaDB
- PostgreSQL
- SQLite (driver dependent)
Fluent builder similar to MysqliDb ergonomics.
Supports named connections and runtime switching.
Supports SAVEPOINT-based nested transaction logic.
Built-in extension points:
- Query Logging
- Metrics
- Auditing
- Retry logic
Built-in pagination helper.
Just include file:
require_once 'PdoDb.php';$db = PdoDb::create([
'default' => [
'dsn' => 'mysql:host=localhost;dbname=test_db;charset=utf8mb4',
'username' => 'root',
'password' => 'secret'
]
]);$users = $db->get('users');$users = $db
->where('active', 1)
->orderBy('created_at', 'DESC')
->limit(10)
->get('users');$user = $db->where('id', 42)->getOne('users');$count = $db->getValue('users', 'COUNT(*)');$id = $db->insert('users', [
'username' => 'john',
'email' => 'john@example.com'
]);$db->insertMulti('users', [
['username' => 'user1'],
['username' => 'user2']
]);$db->where('id', 42)->update('users', [
'active' => 0
]);$db->where('last_login', '2023-01-01', '<')
->delete('users');$db->where('id', 1);
$db->orWhere('status', 'active');$db->join('profiles', 'users.id = profiles.user_id', 'INNER');$db->groupBy('role');$db->orderBy('created_at', 'DESC');$db->limit(10)->offset(20);$db->rawQuery("SELECT * FROM users WHERE id > ?", [100]);$db->rawQueryOne("SELECT * FROM users WHERE id = ?", [1]);$db->rawQueryValue("SELECT COUNT(*) FROM users");$result = $db->paginate('users', 1, 20);Returns:
[
data => [...],
pagination => ...
]
$db->startTransaction();
try {
$db->insert('logs', ['msg' => 'start']);
$db->commit();
} catch (Exception $e) {
$db->rollback();
}$db->startTransaction();
$db->startTransaction(); // Savepoint
$db->commit();
$db->commit();$analytics = $db->withConnection('analytics');$db->debug(true);
print_r($db->queryLog());$hooks->afterQuery = function($ctx) {
if ($ctx['duration_ms'] > 500) {
error_log("Slow Query");
}
};✔ Prepared Statements Only
✔ Safe Parameter Binding
✔ Identifier Validation
✔ No SQL Injection Risk
Optimized for:
- OPcache
- Low memory allocation
- Statement reuse
- Future connection pooling
❌ Not ORM
❌ Not ActiveRecord
❌ Not Framework
❌ Not Migration Tool
✔ SaaS Backends
✔ REST APIs
✔ Microservices
✔ High Traffic Systems
✔ Enterprise PHP Systems
MIT