PHPackages                             wtframework/dbal - 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. wtframework/dbal

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

wtframework/dbal
================

What the Framework?! DBAL

v0.3.0(1y ago)04041MITPHPPHP ^8.2

Since Jan 20Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (11)Used By (1)

What the Framework?! DBAL
=========================

[](#what-the-framework-dbal)

This library extends the [SQL](https://github.com/wtframework/sql) library with a wrapper for PDO.

The [ORM](https://github.com/wtframework/orm) library extends this library to provide object–relational mapping.

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

[](#installation)

```
composer require wtframework/dbal
```

Documentation
-------------

[](#documentation)

### Configuration

[](#configuration)

[MariaDB](docs/mariadb.md)
[MySQL](docs/mysql.md)
[SQLite](docs/sqlite.md)
[PostgreSQL](docs/postgresql.md)
[SQL Server](docs/sqlserver.md)

### Executing an unprepared statement

[](#executing-an-unprepared-statement)

Use the `unprepared` method to execute an unprepared statement.

```
$response = DB::unprepared("SELECT * FROM users");

$response = DB::select()->from("users")->unprepared();
```

### Preparing a statement

[](#preparing-a-statement)

Use the `prepare` method to prepare a statement.

```
$response = DB::prepare("SELECT * FROM users WHERE user_id = ?");

$response = DB::select()->from("users")->where("user_id", "?")->prepare();
```

Use the `bind` method to bind any parameters.

```
$response->bind(1);
```

Use the `execute` method to execute the statement

```
$response->execute();
```

### Preparing and executing a statement

[](#preparing-and-executing-a-statement)

Use the `execute` method to prepare and execute a statement.

```
$response = DB::execute("SELECT * FROM users WHERE user_id = ?", 1);

$response = DB::select()->from("users")->where("user_id", 1)->execute();
```

When using the statement builder you may also execute the statement by calling it as a function.

```
DB::insert()->into("users")();
```

### Retrieving a result set

[](#retrieving-a-result-set)

Use the `get` method to return a single row result set.

```
DB::get("SELECT * FROM users WHERE user_id = ?", 1);

DB::select()->from("users")->where("user_id", 1)->get();
```

You may also use the `get` method on any response.

```
$response->get();
```

Use the `all` method to return the result set as an array.

```
DB::all("SELECT * FROM users");

DB::select()->from("users")->all();
```

You may also use the `all` method on any response.

```
$response->all();
```

### Miscellaneous

[](#miscellaneous)

Use the `insertID` method after executing a statement to return the last insert ID.

```
DB::insert()->into("users")->execute();

DB::insertID();
```

Use the `affectedRows` method after executing a statement to return the number of rows inserted or updated.

```
$response = DB::update()->table("users")->set('active', 1)->execute();

$response->affectedRows();
```

### Transactions

[](#transactions)

Use the `beginTransaction`, `commit`, and `rollback` methods to perform transactions.

```
DB::beginTransaction();
DB::commit();
DB::rollBack();
```

You may also use the `transaction` method to automatically begin a transaction that will commit on success or roll back on failure.

```
DB::transaction(function ()
{

  DB::insert()->into("users")->execute();

  // ...

});
```

### Using a non-default database connection

[](#using-a-non-default-database-connection)

If you have more than one connection and wish to use a non-default connection then you may use the `connection` method passing it the connection name. This will return an instance of `WTFramework\DBAL\Connection` which shares the same methods as those documented above.

```
$response = DB::connection("mirror")->select()->from("users")->where("user_id", 1)->get();
```

### Statements

[](#statements)

Each of these static methods will return a fluent interface for generating SQL statement strings. See the [SQL](https://github.com/wtframework/sql) library for further documentation.

```
use WTFramework\DBAL\DB;

DB::select();
DB::insert();
DB::replace();
DB::update();
DB::delete();
DB::truncate();

DB::create();
DB::alter();
DB::drop();
DB::createIndex($name);
DB::dropIndex($name);
```

### Services

[](#services)

Each of these static methods will return a service class. See the [SQL](https://github.com/wtframework/sql) library for further documentation.

```
DB::bind($value);
DB::column($name);
DB::constraint($name);
DB::cte($name, $stmt);
DB::index($name);
DB::outfile($path);
DB::partition($name);
DB::raw($string);
DB::subpartition($name);
DB::subquery($stmt);
DB::table($name);
DB::upsert();
DB::window($name);
```

Extending the library
---------------------

[](#extending-the-library)

To extend the library you can use the static `macro` method, passing the new method name and a closure to call. This works for both static and non-static methods. This is available on the `DB`, `Connection`, and `Response` classes.

```
use WTFramework\DB\DB;

DB::macro('count', function (string $table)
{

  return static::select()
  ->column('COUNT(*) AS counter')
  ->from($table)
  ->get()
  ->counter;

});
```

```
DB::count('users');
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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 ~26 days

Recently: every ~2 days

Total

10

Last Release

612d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/593fc3635659d661daf87a3debf99abd502bc0f7e4cce916319d37143775c8da?d=identicon)[wtframework](/maintainers/wtframework)

---

Top Contributors

[![MichaelRushton](https://avatars.githubusercontent.com/u/49325097?v=4)](https://github.com/MichaelRushton "MichaelRushton (13 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/wtframework-dbal/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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