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

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

peterujah/db-controller
=======================

Php PDO databse wrapper.

1.8(2y ago)465MITPHPPHP ^7.0 || ^8.0

Since Dec 21Pushed 2y ago2 watchersCompare

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

READMEChangelog (8)DependenciesVersions (9)Used By (0)

DBController
============

[](#dbcontroller)

DBController is a PHP PDO wrapper that provides a convenient way to interact with a database using the PDO extension.

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

[](#installation)

You can install the package via Composer by running the following command:

```
composer require peterujah/db-controller
```

USAGES
======

[](#usages)

To use DBController, follow these easy steps.

1. Create an instance of the DBController class by passing the database configuration as an array or a path to a configuration file that returns array.

```
use Peterujah\NanoBlock\DBController;
// Pass the configuration as an array
$config = [
    'VERSION' => 'mysql',
    'HOST' => 'localhost',
    'PORT' => 3306,
    'NAME' => 'my_database',
    'USERNAME' => 'root',
    'PASSWORD' => 'password',
];

$handler = new DBController($config);
```

Or extend `\Peterujah\NanoBlock\DBController` to set your connection details like below

```
class Conn extends \Peterujah\NanoBlock\DBController{
	public function __construct(bool $development = false){
 		$config = array(
			"PORT" => 3306,
			"HOST" => "localhost",
			"VERSION" => "mysql",
		);
		if($development){
			$config["USERNAME"] = "root";
			$config["PASSWORD"] = "";
			$config["NAME"] = "dbname";
		}else{
			$config["USERNAME"] = "dbusername";
			$config["PASSWORD"] = "dbpass";
			$config["NAME"] = "dbname";
		}
		$this->onDebug = $development;
		parent::__construct($config);
	}
}
```

Initialize your custom class

```
$handler = new Conn($_SERVER["HOST_NAME"]=="localhost");
```

Now run query select, insert, update, delete etc.. using prepare statment

```
$handler->prepare('SELECT * FROM users WHERE username = :username LIMIT 1');
$handler->bind(':username', "Peter");
$handler->execute();
$res = $handler->getOne();
$handler->free();
```

Or run query select, insert, update, delete etc.. using query

```
$handler->query('SELECT * FROM users');
$res = $handler->getAll();
$handler->free();
```

Customization
=============

[](#customization)

Customize the configuration or enable debugging as needed.

```
// Set a configuration value
$handler->setConfig('VERSION', 'pgsql');

// Enable debugging mode
$handler->setDebug(true);
```

Error Handling
==============

[](#error-handling)

DBController provides error handling for database operations. You can retrieve the error information using the `error()` or `errorInfo()` methods.

```
// Get the error information for the last statement execution
$errorInfo = $handler->error();

// Print the error message
if ($errorInfo !== null) {
    echo "Error: " . $errorInfo[2];
}
```

Debugging
=========

[](#debugging)

You can enable debugging mode to get more detailed information about the executed statements by calling the `dumpDebug()` method.

```
// Enable debugging mode
$handler->setDebug(true);

// Dump the debug information for the last statement execution
$handler->dumpDebug();
```

Methods
=======

[](#methods)

Use the various methods provided by the DBController class to interact with the database.

```
// Prepare a statement
$query = 'SELECT * FROM users WHERE id = :id';
$handler->prepare($query);

// Bind values to parameters
$handler->bind(':id', 1);

//Binds a variable to a parameter.
$handler->param(':id', 1, DBController::_INT)

// Execute the statement
$handler->execute();

// Fetch a single row as an object
$user = $handler->getOne();

// Fetch all rows as an array of objects
$users = $handler->getAll();

// Get the number of rows affected by the last statement execution
$rowCount = $handler->rowCount();

// Get the last inserted ID
$lastInsertId = $handler->getLastInsertId();

// Free up the statement cursor
$handler->free();
```

OptionsDescriptionprepare(string)Call "prepare" with sql query string to prepare query executionquery(string)Call "query" width sql query without "bind" and "param"bind(param, value, type)Call "bind" to bind value to the pdo prepare methodparam(param, value, type)Call "param" to bind parameter to the pdo statmentexecute()Execute prepare statmentrowCount()Get result row countgetOne()Get one resault row, this is useful when you set LIMIT 1getAll()Retrieve all resultgetInt()Gets integer useful when you select COUNT()getAllObject()Gets result objectgetLastInsertedId()Gets list inserted id from tablefree()Free database connectiondumpDebug()Dump debug sql query parametererrorInfo()Print PDO prepare statment error when debug is enablederror()Print connection or execution error when debug is enabledsetDebug(bool)Sets debug statussetConfig(array)Sets connection config arrayconn()Retrieve DBController Instance useful when you call "setConfig(config)"Configuration format
====================

[](#configuration-format)

Connection config array example

```
[
     PORT => 3306,
     HOST => "localhost",
     VERSION => "mysql",
     NAME => "dbname",
     USERNAME => "root",
     PASSWORD => ""
]
```

Contributing
============

[](#contributing)

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.

License
=======

[](#license)

```
DBController is open-source software licensed under the MIT license.
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

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

Recently: every ~117 days

Total

8

Last Release

939d ago

Major Versions

0.1 → 1.22022-02-18

### Community

Maintainers

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

---

Top Contributors

[![peterujah](https://avatars.githubusercontent.com/u/16369609?v=4)](https://github.com/peterujah "peterujah (22 commits)")

---

Tags

databaselibrarymysqlpdodatabase classmysl PDO

### Embed Badge

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

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

###  Alternatives

[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)[sorskod/db

PDO wrapper. Extends PDO and PDOStatement with useful methods.

788.1k2](/packages/sorskod-db)

PHPackages © 2026

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