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

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

cymapgt/db
==========

Light wrapper around Doctrine DBAL library

3.0.1(6y ago)1154[1 PRs](https://github.com/cymapgt/DB/pulls)1BSD-3-clausePHPPHP &gt;=7.2.0CI failing

Since May 18Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/cymapgt/DB)[ Packagist](https://packagist.org/packages/cymapgt/db)[ Docs](https://github.com/cymapgt/DB)[ RSS](/packages/cymapgt-db/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (10)Used By (1)

DB
==

[](#db)

Description
-----------

[](#description)

Light Wrapper around Docrines DBAL to handle management of configuration settings for various database types

Installing
----------

[](#installing)

### Install application via Composer

[](#install-application-via-composer)

require "cymapgt/db": "1.\*"

Usage
-----

[](#usage)

The DB package is built for building database connection settings for various database types supported by Doctrine DBAL

### Overview

[](#overview)

- DB is a singleton, which is common pattern used for database connection classes
- DB is designed to pick DB connection settings from environment variables, but can also take a parameter of database connection settings
- All the Public Methods of the DB package are static
- NB: Storing database parameters in environment variable needs careful considerations Security considerations are needed to ensure that they are only accessible to the web server user. If this method is not viable in your scenario, you may use the alternative method that accepts the DB connect settings as an array.

### Getters and Setters

[](#getters-and-setters)

\####Setting The Database Type

```
DB::setDbType('mysql');

```

Replace mysql with either of the following: oracle, mssql, sqlite, sybase, drizzle, postgres

\####Getting The Database Type of a Connection

```
DB::getDbType();

```

\####Get Database Parameters

```
DB::getDatabaseParameters();

```

Return an array of the database parameters stored in the web server / operating system environment. The array is an associative array whose indices vary depending on the database type. Database configuration array keys match the Doctrine DBAL database connection settings listed on the documentation for DBAL ().

An example for MySQL is the array would contain user, password, host, port, dbname, driver, unix\_socket and charset indices.

### Quality Check on the Configuration Settings

[](#quality-check-on-the-configuration-settings)

#### Validating Configuration Settings

[](#validating-configuration-settings)

```
DB::validateDbParameters($dbParams);

```

Accepts an array of the DB parameters. It then does two checks. It ensures that the driver which DBAL will use for the database is actually loaded. It then checks that any of the default settings any of the various databases DBAL can load are present in the array. If any of the two checks fails a cymapgt\\Exception\\DBException will be thrown.

```
DB::sanitizeDbParameters($dbParams);

```

Accepts an array of the DB parameters. Some of the DB connection settings are optional e.g. the charset in mysql. This method discards empty configurations prior to the DB connection being instantiated.

### Making DB connection and returning a DBAL instance

[](#making-db-connection-and-returning-a-dbal-instance)

#### Connecting from Environment Settings

[](#connecting-from-environment-settings)

```
//dbObj is an instance of DBAL loading your favourite DB . You can make your queries
$dbObj = DB::connectDb();

```

#### Connecting with an Array of config settings

[](#connecting-with-an-array-of-config-settings)

```
DB::setDbType('mysql');

//define settings in array
$mysqlSettings = array (
 'user' => 'cr7',
 'password' => 'valdebas',
 'host' => 'localhost',
 'port' => '3306',
 'dbname' => 'undecima'
);

//return dbal instance with the mysql dbl loaded
$dbObj = DB::connectDbNew($mysqlSettings);

```

#### Closing Database Connections

[](#closing-database-connections)

```
//Part of resource management and ensuring sensitive information is discarded is destroying resources after use
DB::closeDbConnection();

```

### Testing

[](#testing)

DB Tests are provided with the package. SQLITE db is used in the testsuite.

### Contribute

[](#contribute)

- Email @rhossis or contact via Skype
- Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
- You will be added as author for contributions ... duh :)

### License

[](#license)

BSD 3 CLAUSE

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance53

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% 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 ~265 days

Recently: every ~357 days

Total

7

Last Release

2428d ago

Major Versions

1.0.2 → 2.0.02018-04-03

2.0.1 → 3.0.02019-09-24

PHP version history (3 changes)1.0.1PHP &gt;=5.4.0

2.0.0PHP &gt;=7.0.0

3.0.0PHP &gt;=7.2.0

### Community

Maintainers

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

---

Top Contributors

[![cymapgt](https://avatars.githubusercontent.com/u/12482626?v=4)](https://github.com/cymapgt "cymapgt (12 commits)")[![rhossis](https://avatars.githubusercontent.com/u/7324938?v=4)](https://github.com/rhossis "rhossis (1 commits)")

---

Tags

Doctrine DBAL Wrapper

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)

PHPackages © 2026

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