PHPackages                             abrahanzarza/dbm - 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. abrahanzarza/dbm

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

abrahanzarza/dbm
================

Tool for database querying in PHP projects.

1.0.0(1y ago)04MITPHPPHP ^8.3

Since Jun 19Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AbrahanZarza/dbm)[ Packagist](https://packagist.org/packages/abrahanzarza/dbm)[ RSS](/packages/abrahanzarza-dbm/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

Dbm
===

[](#dbm)

[![PHP](https://camo.githubusercontent.com/54b7804384d76a107e2ed3874a2715c33f236220aba6986869de4a3db326eb40/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e332d626c7565)](https://camo.githubusercontent.com/54b7804384d76a107e2ed3874a2715c33f236220aba6986869de4a3db326eb40/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e332d626c7565)

This library provides mechanisms to connect to a database and perform queries easily and conveniently, leveraging all the advantages of the [PHP PDO](https://www.php.net/manual/es/book.pdo.php) extension. It currently supports connections with MySQL, Postgres, and SQLite databases.

It was designed to be used in simple PHP projects but can also serve as the database layer for a more complex web application.

How to start
------------

[](#how-to-start)

Install it in your PHP project using [composer](https://getcomposer.org/doc/):

```
composer require abrahanzarza/dbm

```

With that you are ready to connect with your database.

### MySQL database connection

[](#mysql-database-connection)

```
$dbm = Dbm::build(
    ConnectionType $type,  //ConnectionType::MYSQL
    string $host,
    int $port,
    string $user,
    string $password,
    string $database,
    string $charset = 'utf8mb4',
);

```

Example:

```
$dbm = Dbm::build(ConnectionType::MYSQL, 'localhost', 3306, 'db_user', 'db_pass', 'database', 'latin1');

```

### PostgreSQL database connection

[](#postgresql-database-connection)

```
$dbm = Dbm::build(
    ConnectionType $type,  //ConnectionType::PGSQL
    string $host,
    int $port,
    string $user,
    string $password,
    string $database,
);

```

Example:

```
$dbm = Dbm::build(ConnectionType::PGSQL, 'localhost', 3306, 'db_user', 'db_pass', 'database');

```

### SQLite database connection

[](#sqlite-database-connection)

```
$dbm = Dbm::buildForSqlite(
    string $dbFilePath,  //The database file location
);

```

Example:

```
$dbm = Dbm::buildForSqlite(__DIR__ . '/database.sqlite');

```

How to use
----------

[](#how-to-use)

Once you have been connected successfully following the previous steps, you can work with your database.

### The `read` method

[](#the-read-method)

This method must be used for all **read operations** with your database, for example:

```
$result = $dbm->read('SELECT * FROM users');

```

> The `$result` variable contains an array with all records of the users table.

#### Available parameters

[](#available-parameters)

NameTypeDescriptionOptionalDefault value$querystringThe database queryNo$parametersarrayBind params for your queryYes\[ \]$singleRowboolReturns only a single rowYesfalse### The `write` method

[](#the-write-method)

This method must be used for all **write operations** with your database, for example:

- Insert one user:

```
$dbm->write(
    'INSERT INTO users (id, name) VALUES (:id, :name)',
    [':id' => 2, ':name' => 'Jane']
);

```

- Update the user:

```
$dbm->write(
    'UPDATE users SET name = :name WHERE id = :id',
    [':name' => 'Lorem', ':id' => 2]
);

```

- Delete the user:

```
$dbm->write('DELETE FROM users WHERE id = :id', [':id' => 2]);

```

- Also, drop the *users* table:

```
$dbm->write('DROP TABLE users');

```

#### Available parameters

[](#available-parameters-1)

NameTypeDescriptionOptionalDefault value$querystringThe database queryNo$parametersarrayBind params for your queryYes\[ \]$returnLastInsertIdboolReturns the last insertion IDYesfalseAuthors
-------

[](#authors)

- [Abrahan Zarza](https://github.com/AbrahanZarza). The project creator and maintainer.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Total

4

Last Release

549d ago

Major Versions

0.1.2 → 1.0.02024-11-16

### Community

Maintainers

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

---

Top Contributors

[![AbrahanZarza](https://avatars.githubusercontent.com/u/35659108?v=4)](https://github.com/AbrahanZarza "AbrahanZarza (6 commits)")

---

Tags

phplibrarymysqlsqlpdoquery

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abrahanzarza-dbm/health.svg)

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

###  Alternatives

[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41249.0k7](/packages/atlas-query)

PHPackages © 2026

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