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

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

openlss/lib-db
==============

PDO wrapper library with helpers

0.0.15(13y ago)3226[1 issues](https://github.com/nullivex/lib-db/issues)3LGPL-3.0+PHPPHP &gt;=5.3.2

Since Mar 21Pushed 13y ago1 watchersCompare

[ Source](https://github.com/nullivex/lib-db)[ Packagist](https://packagist.org/packages/openlss/lib-db)[ Docs](http://openlss.org)[ RSS](/packages/openlss-lib-db/feed)WikiDiscussions master Synced 2mo ago

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

openlss/lib-db
==============

[](#openlsslib-db)

PDO wrapper library with helpers

The Db class tracks query counts and can debug queries. It will auto-generate SQL for insert/update queries.

Usage
=====

[](#usage)

```
//connect
Db::_get()->setConfig($dbconfig)->connect();

//execute a fetch
$result = Db::_get()->fetch('SELECT * FROM `table` WHERE `col` = ?',array($col));
```

Reference
=========

[](#reference)

Call to PDO
-----------

[](#call-to-pdo)

Any functions not shown in the reference are passed directly to PDO

Singleton Information
---------------------

[](#singleton-information)

Db can be and is recommended to be used as a singleton to reuse the same PDO instance.

If multiple connections are needed use a custom method of maintaining the instances.

### ($this) Db::setConfig($config)

[](#this-dbsetconfigconfig)

Sets the config of the database system.

Takes an array with the following structure

```
$config = array(
	 'driver'		=>	'mysql'
	,'database'		=>	'database_name'
	,'host'			=>	'server_host'
	,'port'			=>	'server_port'
	,'user'			=>	'username'
	,'password'		=>	'password'
);
```

### ($this) Db::connect()

[](#this-dbconnect)

Will use the current configuration and connect

### (int) Db::getQueryCount()

[](#int-dbgetquerycount)

Returns the current query count

### (bool) Db::close()

[](#bool-dbclose)

Close the open PDO istance (if any)

### (array) Db::prepWhere($pairs,$type='WHERE')

[](#array-dbprepwherepairstypewhere)

Prepares WHERE strings to be used in queries

- $pairs array of clauses which can be in 4 formats
- 'field-name' =&gt; array($bool='AND',$operator='=',$value)
- 'field-name' =&gt; array($operator='=',$value) //bool defaults to AND
- 'field-name' =&gt; array($operator) //bool defaults to AND, value defaults to NULL
- 'field-name' =&gt; $value //bool defaults to AND, operator defaults to =
- NOTE: use Db::IS\_NULL and Db::IS\_NOT\_NULL for null value operators
- $type specify the start of the string defaults to 'WHERE'
- returns an array, with members:
- \[0\] the resulting WHERE clause; compiled for use with PDO::prepare including leading space (ready-to-use)
- \[n\] the values array; ready for use with PDO::execute

### (int) Db::insert($table,$params=array(),$update\_if\_exists=false)

[](#int-dbinserttableparamsarrayupdate_if_existsfalse)

Insert into a table with given parameters

When $update\_if\_exists is set to TRUE it will perform an INSERT OR UPDATE query.

### (bool) Db::update($table,$keys=array(),$params=array())

[](#bool-dbupdatetablekeysarrayparamsarray)

Updates a record in the database

- $table The table to be updates
- $keys Pairs compatible with prepWhere
- $params Array of name=&gt;value pairs to update with

### (result) Db::fetch($stmt,$params=array(),$throw\_exception=Db::NO\_EXCEPTIONS,$except\_code=null,$flatten=Db::NO\_FLATTEN)

[](#result-dbfetchstmtparamsarraythrow_exceptiondbno_exceptionsexcept_codenullflattendbno_flatten)

Fetches a single row from a query and returns the result

- $stmt The SQL query
- $params Parameters to be bound to the query
- $throw\_exception When set to Db::EXCEPTIONS will throw an exception on result not found
- $except\_cde Code to be throw with the exception
- $flatten When set to Db::FLATTEN will return an array of values from a specific column

### (array result) Db::fetchAll($stmt,$params=array(),$throw\_exception=Db::NO\_EXCEPTIONS,$except\_code=null,$flatten=Db::NO\_FLATTEN)

[](#array-result-dbfetchallstmtparamsarraythrow_exceptiondbno_exceptionsexcept_codenullflattendbno_flatten)

Same as fetch but returns all results in an array

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.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 ~1 days

Total

15

Last Release

4783d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83c8e9d55e3ebafb0621a441a51af8f551f61a274fde5400459a29cc320b7b75?d=identicon)[nullivex](/maintainers/nullivex)

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

---

Top Contributors

[![nullivex](https://avatars.githubusercontent.com/u/2321375?v=4)](https://github.com/nullivex "nullivex (17 commits)")[![Spudz76](https://avatars.githubusercontent.com/u/2391234?v=4)](https://github.com/Spudz76 "Spudz76 (5 commits)")

---

Tags

databasemysqlpdodatabase abstraction

### Embed Badge

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

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

###  Alternatives

[lincanbin/php-pdo-mysql-class

A PHP MySQL PDO class similar to the Python MySQLdb, which supports iterator and parameter binding when using 'WHERE IN' statement.

2386.4k](/packages/lincanbin-php-pdo-mysql-class)

PHPackages © 2026

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