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

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

angrycoders/db
==============

JKUAT App database interface

v1.0.1(11y ago)061MITPHPPHP &gt;=5.4.0

Since Apr 8Pushed 10y ago4 watchersCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

angrycoders/db-driver
=====================

[](#angrycodersdb-driver)

Database driver for [angrycoders/system](https://github.com/angrycoders/system) and ecosystem.

Install
-------

[](#install)

Via Composer

```
$ composer require angrycoders/db
```

Get master branch update

```
$ composer require "angrycoders/db": "dev-master"
```

Get for a specific version

```
$ composer require "angrycoders/db": "1.0.0"
```

Usage
-----

[](#usage)

Make sure your server is running first.

```
require_once __DIR__ . '../vendor/autoload.php';

use AngryCoders\Db\Db;

use AngryCoders\Db\DbException;

$db = new Db();
```

### Adding a new table

[](#adding-a-new-table)

```
$db->createTable(tableName, fields)
```

Creates a new table in the database, if it does **not** exist already.

- `tableName` (string): name of the table
- `fields` (array): associative array describe the table's attributes. See [below](#attrs).

`fields` passed to `createTable`:

```
 $fields = array(
    fieldName1 => array(type, size [, extraAttrb1, extraAttrb2, ... , ...]),
    fieldName2 => array(type, size [, extraAttrib1, extraAttrb2, ... , ...]),
    ...)
```

- `fieldName` (string): name of the attribute
- `type` (constant): **Required.** Constant exposed by the library. Include:
    - `Db::DATETIME`
    - `Db::DOUBLE`
    - `Db::FLOAT`
    - `Db::INTEGER`
    - `Db::TEXT`
    - `Db::VARCHAR`
- `size` (integer): **Required.** Length of field. If a field does not have a size just specify zero (`0`).
- `extraAttrb1, extraAttrb2, ...`: **Optional.** Any other attributes to be applied. For example,
    - `Db::AUTO_INCREMENT`
    - `Db::NOT_NULL`
    - `Db::PRIMARY_KEY`

Example:

```
try {
    $db->createTable("student", array(
            "studentID" => array(Db::INTEGER, 11, Db::PRIMARY_KEY, Db::AUTO_INCREMENT),
            "regNo" => array(Db::VARCHAR, 20),
            "accountID" => array(Db::INTEGER, 11),
            "name" => array(Db::VARCHAR, 50)));
} catch (DbException $e) {
    echo $e;
}
```

### Deleting a table

[](#deleting-a-table)

```
$db->deleteTable(tableName);
```

Removes a table from the database.

- `tableName` (string): table name

Example:

```
$db->deleteTable("tableName");
```

### Inserting a record

[](#inserting-a-record)

```
$db->insertRecord(tableName, values)
```

Inserts a record into the target table.

- `tableName` (string): table name
- `values` (array): array of values to be inserted.

Example:

```
$db -> insertRecord("student", array(NULL, 'cs281-3722/2013', '54', '23', 'Magani Felix'));
```

### Deleting a record

[](#deleting-a-record)

```
$db->deleteRecord(tableName, value, field)
```

Deletes a record from table `tableName` where `field` equals `value`.

- `tableName` (string): name of table
- `value` (Any): value to be compared with
- `field` (string): name of field to be used to search for `value`

Example:

```
$db->deleteRecord("student", 'cs281-3722/2013', "regNo");
```

### Selecting records

[](#selecting-records)

```
$db->getRecord(tableName, field, value [, targetFields])
```

Selects all records from table `tableName` where field `field` contains `value`.

- `tableName` (string): table name
- `field` (string): name of field to used to search for `value`
- `value` (Any): value to be compared with
- `targetFields` (array): **Optional**. Array of field names to return values from. If not passed, all the fields will be used.

Example:

```
$result = $db->getRecord("student", 'name', 'Felix');

foreach($result as $row)
{
    echo $row['studentID'] . "";
    echo $row['regNo'] . "";
    echo $row['courseID'] . "";
    echo $row['name'] . "";
    echo $row['accountID'] . "";
}

$result = $db->getRecord("student", 'name', 'Felix', array('name','accountID'));
foreach($result as $row)
{
    echo $row['name'] . "";
    echo $row['accountID'] . "";
}
```

### Getting records

[](#getting-records)

```
$db->getAllRecords(tableName [, targetFields [, numOfRecords [, startIndex]]])
```

Return all records in table `tableName`.

- `tableName` (string): table name
- `targetFields` (array): **Optional**. Array of field names to return values from. If not passed, all the fields will be used
- `numOfRecords` (integer): **Optional**. number of records to return
- `startIndex` (integer): **Optional**. From which index to fetch records from

Example:

```
$result = $db->getAllRecords("student");

foreach($result as $row)
{
    echo $row['studentID'] . "";
    echo $row['regNo'] . "";
    echo $row['courseID'] . "";
    echo $row['name'] . "";
    echo $row['accountID'] . "";
}

//selecting accountID and name fields only to be returned
$result = $db->getAllRecords("student", array('name','accountID'));

//selecting the first 5 records to be returned
$result = $db->getAllRecords("student", null, 5);

//selecting the next 10 records to be returned from the 5th record
$result = $db->getAllRecords("student", null, 10, 4);
```

### Updating records

[](#updating-records)

```
$db->updateRecord(tableName, fields, values, discriminantField, discriminantValue)
```

Update records in table `tableName` in the fields `fields` with the values `values` where the field `discriminantField` equals `discriminantValue`.

- `tableName` (string): table name
- `fields` (array): array of table fields to target
- `values` (array): array of values to update with
- `discriminantField` (string): name of field to use to compare records with
- `discriminantValue` (Any): value used to compare against

Example:

```
$tableName = "student"; //The name of the table
$fields = array('name', 'accountID'); //Fields to be updated
$values = array('John Doe', '23'); //The new values
$field = 'regNo'; //The field to check
$value = 'cs281'; // The value of the field to check

$db->updateRecord($tableName, $fields, $values, $field, $value);
```

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](https://github.com/angrycoders/db-driver/blob/master/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

[Magani Felix](https://github.com/keysindicet) and [Contributors](https://github.com/angrycoders/jkuatapp-dbapi/graphs/contributors).

License
-------

[](#license)

**The MIT License (MIT)**. Please see [LICENSE.md](https://github.com/angrycoders/db-driver/blob/master/LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

4055d ago

### Community

Maintainers

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

---

Top Contributors

[![GochoMugo](https://avatars.githubusercontent.com/u/4707579?v=4)](https://github.com/GochoMugo "GochoMugo (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/angrycoders-db/health.svg)](https://phpackages.com/packages/angrycoders-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)
