PHPackages                             gonzalo123/db - 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. gonzalo123/db

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

gonzalo123/db
=============

Database Abstraction Layer over DBAL

76PHP

Since Dec 23Pushed 12y ago2 watchersCompare

[ Source](https://github.com/gonzalo123/Db)[ Packagist](https://packagist.org/packages/gonzalo123/db)[ RSS](/packages/gonzalo123-db/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

SQL wrapper
===========

[](#sql-wrapper)

[![Build Status](https://camo.githubusercontent.com/a989b1e9d9e9742760bd9cccd89f1bffc087a69d58cac77dfb2616205b15c6a0/68747470733a2f2f7472617669732d63692e6f72672f676f6e7a616c6f3132332f44622e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/gonzalo123/Db)[![SensioLabsInsight](https://camo.githubusercontent.com/97cfb5e042061d6fe760fb8588717d295279f9a358b4de39433c2d9b9eb87c31/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f64336361333030662d643732332d343231362d623965332d3136383839623363356261382f6269672e706e67)](https://insight.sensiolabs.com/projects/d3ca300f-d723-4216-b9e3-16889b3c5ba8)

First we set up de DBAL connection

```
use Doctrine\DBAL\DriverManager;

// Set up DBAL Connection
$conn = DriverManager::getConnection([
    'driver' => 'pdo_sqlite',
    'memory' => true
]);
```

We also can set up the DBAL connection from a PDO instance

```
$conn = DriverManager::getConnection(['pdo' => new PDO('sqlite::memory:')]);
```

Then we create the database and populate tables with dummy data

```
// init database
$conn->exec("CREATE TABLE users (
            userid VARCHAR PRIMARY KEY  NOT NULL ,
            password VARCHAR NOT NULL ,
            name VARCHAR,
            surname VARCHAR
            );");
$conn->exec("INSERT INTO users VALUES('user','pass','Name','Surname');");
$conn->exec("INSERT INTO users VALUES('user2','pass2','Name2','Surname2');");
```

Now we can use the library:

```
use G\Sql;
use G\Db;

// setting up G\Db with connection
$db = new Db($conn);

// select from string
$data = $db->select("select * from users");
// select from table
$data = $db->select(SQL::createFromTable("users"));
// select from table with where clause
$data = $db->select(SQL::createFromTable("users", ['userid' => 'user2']));
// iterating select statement changing the recordset
$data = $db->select(SQL::createFromTable("users"), function (&$row) {
    $row['name'] = strtoupper($row['name']);
});
// transactions
$db->transactional(function (Db $db) {
    $userId = 'temporal';

    $db->insert('users', [
        'USERID'   => $userId,
        'PASSWORD' => uniqid(),
        'NAME'     => 'name3',
        'SURNAME'  => 'name3'
    ]);

    $db->update('users', ['NAME' => 'updatedName'], ['USERID' => $userId]);
    $db->delete('users', ['USERID' => $userId]);
});
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c5bcdeee0f7e214945e0d27310df0ad487e7d1ec10a8d4341dbdcabfac58f2f7?d=identicon)[gonzalo123](/maintainers/gonzalo123)

---

Top Contributors

[![gonzalo123](https://avatars.githubusercontent.com/u/39072?v=4)](https://github.com/gonzalo123 "gonzalo123 (7 commits)")

### Embed Badge

![Health badge](/badges/gonzalo123-db/health.svg)

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

###  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)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

PHPackages © 2026

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