PHPackages                             mistralys/application-dbhelper - 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. mistralys/application-dbhelper

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

mistralys/application-dbhelper
==============================

PHP database abstraction layer using PDO.

08PHPCI failing

Since Nov 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Mistralys/application-dbhelper)[ Packagist](https://packagist.org/packages/mistralys/application-dbhelper)[ RSS](/packages/mistralys-application-dbhelper/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/3629bd9cb5bd5e283b45959b641477e916afa70b72dcc18e4383393547080bd2/68747470733a2f2f7472617669732d63692e636f6d2f4d69737472616c79732f6170706c69636174696f6e2d646268656c7065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/Mistralys/application-dbhelper)

DBHelper
========

[](#dbhelper)

PHP Database abstraction layer.

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

[](#installation)

Simply require the package via composer:

```
"require": {
   "mistralys/application-dbhelper": "dev-master"
}

```

Configuration
-------------

[](#configuration)

To get started, at least one database connection has to be added:

```
$database = DBHelper::addDatabase('identifier', 'database_name')
->setHost('somehost') // default is localhost
->setCredentials('username', 'password')
->setPort(1234); // omit to use default port
```

Once all databases and optional event handlers have been added, the helper has to be initialized manually once:

```
DBHelper::init()
```

### Database init command

[](#database-init-command)

A database connection can be configured further with an init command, which is run when the connection is established. Typically, this is used to set the encoding of the connection.

```
$database->setInitCommand('SET NAMES latin1');
```

Methods overview
----------------

[](#methods-overview)

### Fetching single records

[](#fetching-single-records)

- **fetch**: Gets a record's data from a custom SQL statement.
- **fetchData**: Gets a record's data, building the SQL statement dynamically.
- **fetchKey**: Gets a record's data, and returns the specified column value.

### Fetching multiple records

[](#fetching-multiple-records)

- **fetchAll**: Gets all entries from a custom SQL statement.
- **fetchAllKey**: Gets an indexed array with a single column's values from a custom SQL statement.

### Deleting records

[](#deleting-records)

- **delete**: Deletes records using a custom SQL statement.
- **deleteRecords**: Deletes records, building the SQL statement dynamically.

### Transactions

[](#transactions)

- **startTransaction**: Starts a transaction.
- **commitTransaction**: Commits an active transaction.
- **rollbackTransaction**: Rolls back an active transaction.

### Table-related

[](#table-related)

- **columnExists**: Check if a specific column exists in a table.
- **fetchTableNames**: Retrieves the names of all tables in the database.
- **dropTables**: Drops all tables in the database.
- **tableExists**: Checks whether the specified table exists in the database.
- **isAutoincrementColumn**: Checks whether a column is an auto increment column.

### Debugging and logging

[](#debugging-and-logging)

- **countQueries**: Counts the amount of queries executed up to this point (requires query tracking).
- **countSelectQueries**: Counts the amount of SELECT queries executed up to this point (requires query tracking).
- **countWriteQueries**: Counts the amount of database write operations executed up to this point (requires query tracking).
- **enableDebugging**: Enables query debugging, which will echo all SQL statements after this call.
- **enableQueryTracking**: Enables saving all queries to memory to be able to access them later.
- **disableDebugging**: Disable debugging again after enabling it.
- **disableQueryTracking**: Disables query tracking again after enabling it.
- **getSelectQueries**: Retrieves all SELECT SQL statements executed up to this point (requires query tracking).
- **getWriteQueries**: Retrieves all write operation SQL statements executed up to this point (requires query tracking).
- **getQueryCount**: Returns the total amount of queries executed up to this point.
- **getQueries**: Retrieves all SQL statements executed up to this point (requires query tracking).
- **setLogCallback**: Sets a callback to call for handling log messages.

Event handling
--------------

[](#event-handling)

There are currently two events that listeners can be added to:

1. `Init`: Called when initialization is complete, a connection to the database was successful, and queries can be run.
2. `OnBeforeWriteOperation`: Called whenever a write operation is about to be executed. Allows cancelling the operation.

Both events have their own method to add callback functions or methods as event listeners.

```
DBHelper::onInit('handle_initDatabase');
DBHelper::onBeforeWriteOperation('handle_beforeWriteOperation');
```

The callback function always gets the event object as first parameter. Additional arguments can optionally be specified in the arguments parameter:

```
 DBHelper::onInit(
     'handle_initDatabase',
     array(
         'foo',
         'bar'
     )
);

function handle_initDatabase(\AppDB\DBHelper_Event $event, $param1, $param2)
{
    // $param1 = 'foo'
    // $param2 = 'bar'
}
```

Origin
------

[](#origin)

Historically, these classes were integrated in several legacy applications. This repository aims to centralize the code and to make it easier to test and maintain them.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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://avatars.githubusercontent.com/u/8895528?v=4)[Mistralys](/maintainers/Mistralys)[@Mistralys](https://github.com/Mistralys)

---

Top Contributors

[![Mistralys](https://avatars.githubusercontent.com/u/8895528?v=4)](https://github.com/Mistralys "Mistralys (43 commits)")

### Embed Badge

![Health badge](/badges/mistralys-application-dbhelper/health.svg)

```
[![Health](https://phpackages.com/badges/mistralys-application-dbhelper/health.svg)](https://phpackages.com/packages/mistralys-application-dbhelper)
```

###  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)
