Search by

byjg / anydataset-db

byjg

AnyDataset-DB provides a relational database abstraction layer. It is part of the Anydataset project, an agnostic data source abstraction layer for PHP.

Package info

github.com/byjg/php-anydataset-db

pkg:composer/byjg/anydataset-db

Statistics

Installs: 97 239

Dependents: 3

Suggesters: 0

Stars: 5

Open Issues: 0

6.0.1 2026-07-01 14:49 UTC

README

sidebar_key anydataset-db
tags
php anydataset databases

Database Abstraction Layer

AnyDataset-DB provides a relational database abstraction layer. It is part of the Anydataset project, an agnostic data source abstraction layer for PHP.

Sponsor Build Status Opensource ByJG Install MCP Server GitHub source GitHub license GitHub release

Learn more about Anydataset here.

Features

  • Connection based on URI
  • Handles compatibility and code optimization across multiple databases (e.g., MySQL, PostgreSQL, MS SQL Server)
  • Built-in Query Cache support using a PSR-16 compliant interface
  • Enables connection routing based on regular expressions for queries (e.g., directing queries to different databases for specific tables)

Connection Based on URI

Database connections are defined using URL-based connection strings.

Supported drivers are listed below:

Database Connection String Factory Method
SQLite sqlite:///path/to/file getDbInstance()
DuckDB duckdb:///path/to/file (duckdb:// for in-memory) getDbInstance()
MySQL/MariaDB mysql://username:password@hostname:port/database getDbInstance()
PostgreSQL pgsql://username:password@hostname:port/database getDbInstance()
SQL Server (DbLib) dblib://username:password@hostname:port/database getDbInstance()
SQL Server (Sqlsrv) sqlsrv://username:password@hostname:port/database getDbInstance()
Oracle (OCI8) oci8://username:password@hostname:port/database getDbInstance()
Oracle (PDO OCI) oci://username:password@hostname:port/database getDbInstance()
Generic PDO pdo://username:password@pdo_driver?PDO_PARAMETERS getDbInstance()
Cloudflare D1 d1://account_id:api_token@api.cloudflare.com/database_id getDbInstance()

Example usage:

<?php
$conn = \ByJG\AnyDataset\Db\Factory::getDbInstance("mysql://root:password@10.0.1.10/myschema");

Examples

Advanced Topics

Database Specifics

Installation

Just type:

composer require "byjg/anydataset-db"

Running Tests

docker compose up -d
vendor/bin/phpunit

More details, including the database suites, are in Running Unit tests.

Open source ByJG