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

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

power/db
========

Simple static class to work with mysql databases

2.10(3mo ago)1234BSD-3-ClausePHPPHP &gt;=7.0.0

Since Sep 30Pushed 3mo ago1 watchersCompare

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

READMEChangelog (10)DependenciesVersions (13)Used By (0)

Simple static/non-static classes for working with MySql databases

- **PHP version:** 7.0+
- **Composer:** `composer require power/db`
- This code was taken as a basis

#### Two ways to use: static and non/static

[](#two-ways-to-use-static-and-nonstatic)

All methods available in both class types

```
use \Power\DB;

// Non-static
$db = new \Power\mDB('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Select all records from users table
$data = $db->getAll('SELECT * FROM ?n', 'users');

// Static
DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
// Select all records from users table
$data = DB::getAll('SELECT * FROM ?n', 'users');
```

#### Work with one database

[](#work-with-one-database)

```
use \Power\DB;

DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');

// Get one row with some id
$id = 5;
DB::getRow('SELECT * FROM `users` WHERE `id`=?i', $id);

// Get all rows
$login = 'tester';
DB::getAll('SELECT * FROM `logs` WHERE `login`=?s', $login);

// Get one value
DB::getOne('SELECT count(*) FROM `users`');

// Insert some data
$table_name = 'logs';
$data = [
    'create_date' => DB::pure('now()'),  // when you don't need to escape value - use DB::pure method
    'login' => 'tester',
    'userid' => 5
];
DB::query('INSERT INTO ?n SET ?u', $table_name, $data);
// or user insert method
DB::insert($table_name, $data);
// Get inserted id from last query
echo DB::insertId();

// Update records
DB::update($table_name, $data)
```

#### Work with several databases from static class

[](#work-with-several-databases-from-static-class)

```
use \Power\DB;

$db1 = DB::Init('localhost', 'users', 'passwd', 'dbname', 'utf8mb4');
$db2 = DB::Init('localhost', 'users1', 'passwd1', 'dbname1', 'utf8mb4');

// Turn on saving statistics
DB::SetSaveStats(true);
// After initializing, first DB is selected for work
// Get associated array with id field as key
DB::getIndCol('id', 'SELECT `id`,`name` FROM `users`');
// Switching to second database
DB::Switch($db2);
// Get all the rows into indexed array
DB::getInd('id', 'SELECT * FROM `users`');
// Get queries statistics
print_r(DB::getStats());
```

#### Using placeholders

[](#using-placeholders)

```
?n - table or field name
?s - string
?i - number
?a - array for IN, example IN (?a)
?u - array for SET
?p - insert prepared sql without escaping

```

#### Make custom error handler

[](#make-custom-error-handler)

```
use \Power\DB;

function ErrorHandler($message)
{
    die($message);
}
DB::SetErrorHandler('ErrorHandler');
```

#### Save error and query logs to file

[](#save-error-and-query-logs-to-file)

```
use \Power\DB;

DB::Init('localhost', 'user', 'passwd', 'dbname', 'utf8mb4');
DB::SetErrorLog(__DIR__.'/mysql_error.log');
DB::SetLogSql(__DIR__.'/mysql_sql.log', false);
```

#### Use `DBCacheQuery` class to insert a large number of records using fewer queries

[](#use-dbcachequery-class-to-insert-a-large-number-of-records-using-fewer-queries)

```
// Create class and point table name and col names for inserting records
$cache_items = new \DBCacheQuery('item_list', ['id', 'name', 'icon', 'list', 'data_type']);
foreach ($some_data as $data)
{
    // Use Add method for each new row
    // Make sure, that param array has the same data order as you make in class creation
    $cache_items->Add(
    [
        $data['id'],
        $data['name'],
        $data['icon'],
        $data['list'],
        $data['type']
    ]);
}
// Then use Flush method to send the remaining data from the cache
$cache_items->Flush();
// That's all
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance81

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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

Recently: every ~332 days

Total

12

Last Release

103d ago

Major Versions

1.0 → 2.02021-06-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/6689371ddad2e268b759a400ea81d55284a115c950669ce1bc48a645d7782328?d=identicon)[alexdnepro](/maintainers/alexdnepro)

---

Top Contributors

[![alexdnepro](https://avatars.githubusercontent.com/u/29249402?v=4)](https://github.com/alexdnepro "alexdnepro (16 commits)")

### Embed Badge

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

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