PHPackages                             scottchiefbaker/dbquery - 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. scottchiefbaker/dbquery

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

scottchiefbaker/dbquery
=======================

DBQuery is a PHP database library to simplify fetching and iterating over your data.

v1.1.2(1mo ago)16MITPHPPHP &gt;=8.0

Since May 8Pushed 4w ago1 watchersCompare

[ Source](https://github.com/scottchiefbaker/DBQuery)[ Packagist](https://packagist.org/packages/scottchiefbaker/dbquery)[ Docs](https://github.com/scottchiefbaker/DBQuery)[ RSS](/packages/scottchiefbaker-dbquery/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (5)DependenciesVersions (2)Used By (0)

DBQuery
=======

[](#dbquery)

DBQuery is a PHP database library to simplify fetching and iterating over your data. It supports any database that PDO supports, and has been tested extensively with MySQL and SQLite. DBQuery has been tested on PHP versions: 8.1, 8.2 and 8.3.

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

[](#installation)

```
require("include/db_query.class.php");
```

Example Usage
-------------

[](#example-usage)

```
// SQLite
$dsn = "sqlite://path/to/dir/database.sqlite";
$dbq = new DBQuery($dsn);

// MySQL
$dsn  = 'mysql:host=server.domain.com;dbname=my_database';
$user = 'john_smith';
$pass = 'sekrit';
$dbq  = new DBQuery($dsn, $user, $pass);

$sql  = "SELECT First, Last, City, State, Zipcode FROM Customers;";
$data = $dbq->query($sql);

foreach ($data as $rec) {
	// Output code here
}
```

DBQuery simplifies the act of sending queries and iterating over the results. The core of DBQuery is in the `query()` function, which handles sending queries and building an iterable recordset.

```
$result = $dbq->query($sql);
$result = $dbq->query($sql, $return_hint);
$result = $dbq->query($sql, $param_array, $return_hint);
```

DBQuery does its best job to give you the datatype you want, but you can provide hints to guide it.

Return Hints
------------

[](#return-hints)

**info\_hash** return an array of associative arrays (Note: this is the default return type)

```
$sql  = "SELECT First, Last, City FROM Customers;";
$data = $dbq->query($sql, 'info_hash');

foreach ($data as $i) {
	print "Cust: " . $i['First'] . " " . $i['Last'];
}
```

**info\_list** return an array of numeric arrays

```
$sql  = "SELECT First, Last, City FROM Customers;";
$data = $dbq->query($sql, 'info_list');

foreach ($data as $i) {
	print "Cust: " . $i[0] . " " . $i[1];
}
```

**one\_data** return a single scalar

```
$sql = "SELECT CustID FROM Customers WHERE Last = 'Doolis';";
$id  = $dbq->query($sql, 'one_data');
```

**key\_value** return an associative array key/value pair

```
$sql  = "SELECT ID, Last FROM Customers;";
$data = $dbq->query($sql, 'key_value');

print "Customer #17 = " . $data[17];
print "Customer #21 = " . $data[21];
```

**one\_row** return a single associtive array

```
$sql  = "SELECT First, Last FROM Customers WHERE City = 'Chicago';";
$data = $dbq->query($sql, 'one_row');

print "Customer: " . $data['First'] . " " . $data['Last'];
```

**one\_column** return a single numeric array

```
$sql = "SELECT ID FROM Customers WHERE City = 'Chicago';";
$ids = $dbq->query($sql, 'one_column');

print "Found IDs: " . join(", ", $ids);
```

Parameter Binding
-----------------

[](#parameter-binding)

```
$sql    = "INSERT INTO Names (First, Last, Age) VALUES (?, ?, ?);";
$params = array("Jason", "Doolis", 14);

$id = $dbq->query($sql, $params);
```

Unit Tests
----------

[](#unit-tests)

DBQuery contains standalone unit tests which use an in-memory SQLite database to test the functionality of DBQuery. You can run this unit tets from the command line with:

```
php tests/unit_test.php

```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance94

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

33d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9abab1acc5a8df8723cc365fc7cbc437bb9844fd9f0b9d0a8950925b1ae2ff4d?d=identicon)[scottchiefbaker](/maintainers/scottchiefbaker)

---

Top Contributors

[![scottchiefbaker](https://avatars.githubusercontent.com/u/3429760?v=4)](https://github.com/scottchiefbaker "scottchiefbaker (100 commits)")

---

Tags

databasequerydbiterate

### Embed Badge

![Health badge](/badges/scottchiefbaker-dbquery/health.svg)

```
[![Health](https://phpackages.com/badges/scottchiefbaker-dbquery/health.svg)](https://phpackages.com/packages/scottchiefbaker-dbquery)
```

###  Alternatives

[aura/sqlquery

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

4873.1M37](/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.

923530.0k13](/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.

920281.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.

920249.3k8](/packages/fpdo-fluentpdo)[illuminated/db-profiler

Database Profiler for Laravel Web and Console Applications.

168241.0k](/packages/illuminated-db-profiler)[jasny/persist-sql-query

SQL Query builder and parser

33513.5k4](/packages/jasny-persist-sql-query)

PHPackages © 2026

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