PHPackages                             patryknamyslak/patbase - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. patryknamyslak/patbase

ActiveLibrary[Database &amp; ORM](/categories/database)

patryknamyslak/patbase
======================

A highly configurable DB facade and Database interaction interface (Patbase)

v2.2.1(4mo ago)1105[1 issues](https://github.com/PatrykNamyslak/PatBase/issues)3MITPHP

Since Jul 15Pushed 4mo agoCompare

[ Source](https://github.com/PatrykNamyslak/PatBase)[ Packagist](https://packagist.org/packages/patryknamyslak/patbase)[ RSS](/packages/patryknamyslak-patbase/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (2)Versions (15)Used By (3)

Patbase - Type-Safe Multi-Driver Database Abstraction + DB Facade and Query Builder
===================================================================================

[](#patbase---type-safe-multi-driver-database-abstraction--db-facade-and-query-builder)

Stop hardcoding database drivers. Patbase provides a clean, type-safe interface for working with any PDO-supported database.

Features
--------

[](#features)

✅ **DB Facade** - DB Facade + Query builder for faster ship times! \\n ✅ **9 Database Drivers** - MySQL, PostgreSQL, SQLite, SQL Server, Oracle, and more
✅ **Type-Safe** - PHP 8.4 enums prevent invalid drivers
✅ **Zero Config** - Automatic DSN generation and default ports
✅ **Lazy Loading** - Connect only when needed
✅ **Clean API** - Fluent, modern PHP interface
✅ **Exception Handling** - Detailed error messages

Installation
------------

[](#installation)

```
composer require patryknamyslak/patbase
```

Quick Start
-----------

[](#quick-start)

DB Facade + Query Builder
-------------------------

[](#db-facade--query-builder)

```
use PatrykNamyslak\Patbase\Facades\DB;
use PatrykNamyslak\Patbase\Enums\WhereOperator;

// SELECT * FROM `blog` WHERE views < :views;
$selectQuery = DB::select([*])->from("blog")->where("views", WhereOperator::LESS_THAN, 500)->all()
// The all() method runs the query by automatically swapping in the parameters in for the value you set in the where part of the chain!

DB::insert()->into("table")->set("title", "New Post title");
DB::upsert(["title"])->into("table")->...;
// OR
DB::insertOrUpdate()
DB::delete()->from("blog")->where("title", WhereOperator::LIKE, "Flag API");

DB::update()->table("table")->...;
```

Patbase - PDO Abstraction
-------------------------

[](#patbase---pdo-abstraction)

### MySQL

[](#mysql)

```
use PatrykNamyslak\Patbase\Patbase;
use PatrykNamyslak\Patbase\Enums\DatabaseDriver;

$db = new Patbase(
    driver: DatabaseDriver::MYSQL,
    database: 'myapp',
    username: 'root',
    password: 'Password123@',
    host: 'localhost',
    port: NULL, // NULL (or omit as the default is NULL) or your custom port, NULL will default to the port based on driver type i.e MYSQL = 3306
);

$users = $db->query("SELECT * FROM `users`;")->fetchAll();
```

### PostgreSQL

[](#postgresql)

```
$db = new Patbase(
    driver: DatabaseDriver::POSTGRES,
    database: 'myapp',
    username: 'postgres',
    password: 'secret',
    host: 'localhost'
    // port: 5432 (automatic)
);
```

### SQLite

[](#sqlite)

```
$db = new Patbase(
    driver: DatabaseDriver::SQL_LITE,
    database: './database.db'
    // No username/password needed
);
```

Prepared Statements
-------------------

[](#prepared-statements)

```
$user = $db->prepare(
    "SELECT * FROM users WHERE email = :email",
    [':email' => 'user@example.com']
)->fetch();
```

Lazy Loading
------------

[](#lazy-loading)

```
// Don't connect yet
$db = new Patbase(
    driver: DatabaseDriver::MYSQL,
    database: 'myapp',
    username: 'root',
    password: 'secret',
    autoConnect: false
);

// Optionally modify DSN
$db->dsn('mysql:host=127.0.0.1;port=3307;dbname=myapp');

// Connect when ready (or auto-connects on first query)
$db->connect();
```

Supported Databases
-------------------

[](#supported-databases)

DatabaseDriver EnumDefault PortMySQL / MariaDB`DatabaseDriver::MYSQL`3306PostgreSQL`DatabaseDriver::POSTGRES`5432SQLite`DatabaseDriver::SQL_LITE`N/A (file)SQL Server`DatabaseDriver::MS_SQL_SERVER`1433SQL Server (Linux)`DatabaseDriver::MS_SQL_SERVER_LINUX`1433Oracle`DatabaseDriver::ORACLE`1521Firebird`DatabaseDriver::FIREBIRD`3050IBM DB2`DatabaseDriver::IBM_DB2`50000ODBC`DatabaseDriver::OPEN_DATABASE_CONNECTIVITY`50000Advanced Usage
--------------

[](#advanced-usage)

### Custom PDO Options

[](#custom-pdo-options)

```
$db = new Patbase(
    driver: DatabaseDriver::MYSQL,
    database: 'myapp',
    username: 'root',
    password: 'secret',
    options: [
        PDO::ATTR_PERSISTENT => true,
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
    ]
);
```

### Check Connection Status

[](#check-connection-status)

```
if (!$db->isConnected()) {
    $db->connect();
}
```

### Access PDO Directly (Advanced)

[](#access-pdo-directly-advanced)

```
$pdo = $db->connection();
// Use native PDO methods if needed
```

License
-------

[](#license)

MIT

Author
------

[](#author)

**Patryk Namyslak** - [GitHub](https://github.com/PatrykNamyslak)

AI Notice
---------

[](#ai-notice)

This codebase is not written by Artificial intelligence, Only PARTS of the README were generated by Copilot but it used my documented code as reference to make it, so you can say it just turned my scattered documentation into one concise doc.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance57

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~4 days

Total

14

Last Release

125d ago

Major Versions

v1.4 → v2.02026-02-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/65c81cbbb028fa73196ab7a01c410588bc79f2f09350597f58d65f8c5801099f?d=identicon)[PatrykNamyslak](/maintainers/PatrykNamyslak)

---

Top Contributors

[![PatrykNamyslak](https://avatars.githubusercontent.com/u/143219631?v=4)](https://github.com/PatrykNamyslak "PatrykNamyslak (33 commits)")

### Embed Badge

![Health badge](/badges/patryknamyslak-patbase/health.svg)

```
[![Health](https://phpackages.com/badges/patryknamyslak-patbase/health.svg)](https://phpackages.com/packages/patryknamyslak-patbase)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[cable8mm/xeed

Xeed generates new model, seed, Nova resources, database seed, factory and migration files for Laravel &amp; Nova based on data from the existing database table.

872.5k](/packages/cable8mm-xeed)[lion/bundle

Lion-framework configuration and initialization package

122.4k4](/packages/lion-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
