PHP database abstraction library. Provides a unified interface over mysqli, pgsql, PDO, ADOdb, and MDB2. Namespace: MyDb\.
composer install
vendor/bin/phpunit -c phpunit.xml.dist --testsuite "all tests"
vendor/bin/phpunit -c phpunit.xml.dist --testsuite "mysql tests"With env vars (required for integration tests):
DBUSER=tests DBPASS=tests DBHOST=localhost DBNAME=tests vendor/bin/phpunit -c phpunit.xml.dist
PGDBUSER=postgres PGDBHOST=localhost PGDBNAME=tests DBUSER=tests DBPASS=tests DBHOST=localhost DBNAME=tests vendor/bin/phpunit -c phpunit.xml.dist --testsuite "all tests"DB fixture setup:
mysql --default-character-set=utf8mb4 < tests/mysql.sql
psql tests < tests/psql.sql
sqlite3 tests.db ".read tests/sqlite.sql"Core (src/):
src/Db_Interface.phpβ interface all drivers must implementsrc/Generic.phpβ abstract base class with shared logic (escape,limitQuery,haltmsg,addLog,logBackTrace)src/Loader.phpβ runtime driver loader by type string
Drivers β each at src/{Driver}/Db.php, extends Generic, implements Db_Interface:
src/Mysqli/Db.phpβ nativeext-mysqlisrc/Pgsql/Db.phpβ nativeext-pgsql, usespg_connect/pg_execsrc/Pdo/Db.phpβ PDO with configurable$driver(mysql default)src/Adodb/Db.phpβ ADOdb (adodb/adodb-php)src/Mdb2/Db.phpβ extendssrc/Mysqli/Db.php, addsquote(),queryOne(),queryRow()
Tests (tests/):
tests/GenericTest.phpβ unit tests forGenericbase classtests/LoaderTest.phpβ unit tests forLoadertests/Mysqli/DbTest.php,tests/Pdo/DbTest.php,tests/Pgsql/DbTest.php,tests/Mdb2/DbTest.phpβ integration tests per driver- Fixtures:
tests/mysql.sql,tests/psql.sql,tests/sqlite.sqlβ createservice_typestable with seed data
- Every driver class:
namespace MyDb\{Driver};Β· extendsGenericΒ· implementsDb_Interface - Driver type string set via
public $type = 'mysqli';(or'pgsql','pdo','adodb','mdb2') - Required methods:
connect(),disconnect(),query(),next_record(),num_rows(),num_fields(),affectedRows(),seek(),free(),real_escape(),getLastInsertId(),lock(),unlock(),transactionBegin(),transactionCommit(),transactionAbort(),haltmsg(),tableNames() $this->Recordholds current row afternext_record();$this->Rowtracks position$this->linkId= connection resource;$this->queryId= result resource- Error handling: call
$this->halt('message', $line, $file)β logs viahaltmsg() - Integration tests: use
getenv('DBUSER')/getenv('DBPASS')/getenv('DBHOST')/getenv('DBNAME')for MySQL;getenv('PGDBUSER')etc. for PostgreSQL - Test isolation:
setUp()callstransactionBegin(),tearDown()callstransactionAbort() - Indentation: tabs (per
.scrutinizer.yml) - Commit messages: lowercase, descriptive
- Create
src/{Driver}/Db.phpwithnamespace MyDb\{Driver}; - Extend
MyDb\Generic, implementMyDb\Db_Interface - Implement all required methods listed above
- Add test class at
tests/{Driver}/DbTest.phpusing env-var credentials - Add testsuite entry to
phpunit.xml.dist
Run caliber refresh before creating git commits to keep docs in sync with code changes.
After it completes, stage any modified doc files before committing:
caliber refresh && git add CLAUDE.md .claude/ .cursor/ .github/copilot-instructions.md AGENTS.md CALIBER_LEARNINGS.md 2>/dev/nullRead CALIBER_LEARNINGS.md for patterns and anti-patterns learned from previous sessions.
These are auto-extracted from real tool usage β treat them as project-specific rules.