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(2mo ago)1963MITPHP

Since Jul 15Pushed 2mo agoCompare

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

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

40

—

FairBetter than 88% of packages

Maintenance86

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community10

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

71d 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

[byjg/migration-cli

Simple library in PHP for database version control. Supports Sqlite, MySql, Sql Server and Postgres.

1025.2k](/packages/byjg-migration-cli)

PHPackages © 2026

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