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

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

phlib/db-helper
===============

DB helpers to complement phlib/db

3.0.1(1y ago)01.9kLGPL-3.0PHPPHP ^8.0CI passing

Since Apr 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phlib/db-helper)[ Packagist](https://packagist.org/packages/phlib/db-helper)[ RSS](/packages/phlib-db-helper/feed)WikiDiscussions main Synced 2mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

phlib/db-helper
===============

[](#phlibdb-helper)

[![Code Checks](https://camo.githubusercontent.com/9ee3364f602419ac779359173d0c3838f440b1cb1a7bad8be9f8669fb8564d51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f64622d68656c7065722f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/db-helper/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/4a85dca26c2f099c011e136702a233ffbbb0ad847b7e2f3d1f34088c9dbfd3d7/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f64622d68656c7065722e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/db-helper)[![Latest Stable Version](https://camo.githubusercontent.com/0b179fdf331c5ac2f48d4e83a39036b1dc968c6709c0b9902e6e01b0e902499a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f64622d68656c7065722e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/db-helper)[![Total Downloads](https://camo.githubusercontent.com/b60ece18c0ea38177aa4c0e44c1642be9af677f1ebb952cb2fa4afd6f22977b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f64622d68656c7065722e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/db-helper)[![Licence](https://camo.githubusercontent.com/a60365e8423638014146ec92db11ab22783abdf59c1ebd7620119f651fe1ef6a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f64622d68656c7065722e737667)](https://camo.githubusercontent.com/a60365e8423638014146ec92db11ab22783abdf59c1ebd7620119f651fe1ef6a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f64622d68656c7065722e737667)

DB helpers to complement phlib/db

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

[](#installation)

```
composer require phlib/db-helper
```

Usage
-----

[](#usage)

```
// Get an Adapter
$config = [
    'host' => 'localhost',
    'username' => 'myuser',
    'password' => 'mypassword',
    'dbname' => 'mydatabase'
];
$db = new \Phlib\Db\Adapter($config);
```

### BulkInsert

[](#bulkinsert)

Insert and/or update many rows into a table.

This increases the write performance for adding large numbers (eg. thousands+) of rows, over the typical pseudo-prepared statements used by native PDO.

```
$insertFields = [
    'product_id',
    'product_name',
    'product_qty'
];
$updateFields = [
    'product_name',
    'product_qty'
];
$bulkInsert = new BulkInsert($adapter, 'product', $insertFields, $updateFields);

// Many calls to add() will write to the DB in batches
$bulkInsert->add($singleProductData);

// One final manual call to write() to complete
$bulkInsert->write();
```

### QueryPlanner

[](#queryplanner)

Test the number of rows that a `SELECT` statement will query.

```
$queryPlanner = new QueryPlanner($adapter, $sqlSelect);
$queryPlanner->getNumberOfRowsInspected(); // eg. 46234
```

### BigResult

[](#bigresult)

Run a `SELECT` statement which is expected to be slow (eg. &gt;5s) due to quantity of data.

Query buffering is disabled to reduce the time to first row and avoid consuming PHP's memory for the statement result, and MySQL's query timeout is increased.

```
$bigResult = new BigResult($adapter);
$pdoStmt = $bigResult->query($sqlSelect, $bind);
```

Optionally, prevent very large queries from running by using the QueryPlanner inspection:

```
$bigResult = new BigResult($adapter);
$queryRowLimit = 20000000;
$pdoStmt = $bigResult->query($sqlSelect, $bind, $queryRowLimit);
```

License
-------

[](#license)

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance43

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity72

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

Recently: every ~714 days

Total

6

Last Release

458d ago

Major Versions

1.0.2 → 2.0.02021-10-25

2.0.0 → 3.0.02024-04-05

PHP version history (3 changes)1.0.0PHP ^5.6|^7

2.0.0PHP ^7.4 || ^8.0

3.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/135b7ddf9ec91c412e1b18174f81d1ad2bef66e732624195c156717c96b13731?d=identicon)[letssurf](/maintainers/letssurf)

![](https://www.gravatar.com/avatar/10c53cdcfb3a6d299820aecb993521cc1a972baa09fd8f31d2468908cded7e1d?d=identicon)[chrisminett](/maintainers/chrisminett)

---

Top Contributors

[![chrisminett](https://avatars.githubusercontent.com/u/1084019?v=4)](https://github.com/chrisminett "chrisminett (75 commits)")

---

Tags

helpermysqldb

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

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

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

###  Alternatives

[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921274.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921244.9k7](/packages/fpdo-fluentpdo)[danielme85/laravel-log-to-db

Custom Laravel Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel native logging functionality.

135934.5k1](/packages/danielme85-laravel-log-to-db)[colshrapnel/safemysql

A real safe and convenient way to handle MySQL queries.

400103.5k4](/packages/colshrapnel-safemysql)

PHPackages © 2026

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