| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A production-oriented PDO helper for PHP applications that need a small, dependency-free database abstraction with prepared statements, transaction helpers, and predictable error handling.
composer require a1phanumeric/php-mysql-class<?php
use A1phanumeric\DBPDO;
$db = new DBPDO('127.0.0.1', 'app_db', 'app_user', 'secret');
$user = $db->fetch('SELECT id, email FROM users WHERE id = ?', 42);$db->execute(
'UPDATE users SET email = ? WHERE id = ?',
['new-email@example.com', 42]
);$user = $db->fetch('SELECT * FROM users WHERE id = ?', 42);
if ($user === null) {
// Not found or query failed
}$users = $db->fetchAll('SELECT id, email FROM users WHERE status = ?', 'active');$usersByEmail = $db->fetchAll('SELECT id, email FROM users', null, 'email');$db->transaction(function (DBPDO $tx) {
$tx->execute('UPDATE accounts SET balance = balance - ? WHERE id = ?', [100, 1]);
$tx->execute('UPDATE accounts SET balance = balance + ? WHERE id = ?', [100, 2]);
});$db = DBPDO::getInstance('127.0.0.1', 'app_db', 'app_user', 'secret');$db = new DBPDO('127.0.0.1', 'app_db', 'app_user', 'secret', false, [
'persistent' => false,
'timeout' => 5,
'charset' => 'utf8mb4',
'port' => 3306,
]);SQL Server example:
$db = new DBPDO('sql.example.local', 'app_db', 'app_user', 'secret', true, [
'port' => 1433,
'encrypt' => true,
'trust_server_certificate' => false,
]);$db->setQueryLogger(function (string $query, array $params, ?float $durationMs, ?string $error) {
error_log(json_encode([
'query' => $query,
'params' => $params,
'duration_ms' => $durationMs,
'error' => $error,
]));
});If a query fails, inspect:
$lastError = $db->getLastError();Packagist picks up new versions from Git tags.
git tag -a v3.0.0 -m "Release v3.0.0"
git push origin v3.0.0Recommended versioning for these changes: major release (v3.0.0) for a clean SemVer boundary on the upgraded production behavior and API surface.
The legacy class is still included in this repository:
MIT
| Back | FazBrowse Home | New Git URL |