PHPackages                             naga3/qb - 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. naga3/qb

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

naga3/qb
========

Qb: Simple query builder

1.0.7(10y ago)81213MITPHP

Since Jun 23Pushed 10y ago2 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (9)Used By (0)

Qb: Simple query builder
========================

[](#qb-simple-query-builder)

[Japanese README](https://github.com/naga3/qb/blob/master/README.ja.md)

This was assumed per the provision of the back-end API, a simple PDO query builder. I was created in mind is that the write as short as possible the code.

```
$rows = Qb('contact')->toJson();
```

Just only this you can return a list of the contact table in JSON.

Audiences
---------

[](#audiences)

Though it is to use the raw PDO as it is troublesome, who full-fledged DB library feels overkill function.

Resources
---------

[](#resources)

doc/index.html is a reference.

- GitHub
- Packagist

How to install
--------------

[](#how-to-install)

only require 'qb.php'.

If you use the Composer is,

```
composer require naga3/qb

```

Install Now you read in the autoload.

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

Samples
-------

[](#samples)

sample/contact.php is a sample of a simple contact list. sample/todo.php is a sample of the ToDo list that combines AngularJS. Both samples PDO\_SQLITE module is I will work as it is if it is introduced.

API
===

[](#api)

Connection
----------

[](#connection)

```
Qb::connect('sqlite:sample.db');
Qb::connect('mysql:host=localhost;dbname=sample', 'user', 'pass');
```

Connect to the specified DSN.

SELECT
------

[](#select)

```
$rows = Qb('contact')->toJson();
```

It will return a list of the contact table in JSON.

```
$rows = Qb('contact')->select('name')->select('tel')->toArray();
```

It will return the name column and tel column of the table contact list in the array.

```
$rows = Qb('contact')->select(['name', 't' => 'tel'])->toObject();
```

name column of the table contact list I returned unchanged. And tel column will return as an object with an alias t.

WHERE
-----

[](#where)

```
$row = Qb('contact')->where('id', 1)->oneArray();
```

id column of contact table will return one line of 1.

```
$row = Qb('contact')->where(1)->oneArray(); // In the case of id column, it can be omitted column specified
$row = Qb('contact')->oneArray('id', 1);
$row = Qb('contact')->oneArray(1);
```

There is also such shorthand.

```
$rows = Qb('contact')->whereGte('status', 1)->whereLike('name', '%Yamada%')->toJson();
```

In status column of the contact table is 1 or more, it will return the ones that contain "Yamada" in the name.

JOIN
----

[](#join)

```
$rows = Qb('contact')->join('access', 'access.contact_id = contact.id')->toJson();
```

INNER JOIN. 'access.contact\_id = contact.id' is binding conditions.

```
$rows = Qb('contact')->leftJoin('access', 'access.contact_id = contact.id')->toJson();
```

LEFT OUTER JOIN.

INSERT
------

[](#insert)

```
$id = Qb('contact')->save(['name' => 'Ichiro Suzuki', 'age' => 19]);
```

to contact table name column is "Ichiro Suzuki", insert the record age column is "19". The return value is the value of the primary key.

INSERT or UPDATE
----------------

[](#insert-or-update)

```
Qb('contact')->where('age', 20)->save(['name' => 'Ichiro Suzuki', 'age' => 19]);
```

In an attempt to first UPDATE If there is a WHERE clause to INSERT if there is no record of the target.

UPDATE
------

[](#update)

```
Qb('contact')->where('age', 20)->update(['name' => 'Ichiro Suzuki', 'age' => 19]);
```

Here even if there is no record of the target will not be INSERT.

```
Qb('contact')->where('age', 20)->update('name', 'Ichiro Suzuki');
```

1 column only change you can also be written as this.

SET
---

[](#set)

```
Qb('contact')->where('age', 20)->set('age', 19)->set('name', 'Ichiro Suzuki')->update();
```

INSERT and from connecting the chain set, you can UPDATE.

DELETE
------

[](#delete)

```
Qb('contact')->where('age', 20)->delete();
```

age column of contact table will remove all 20 of the record.

```
Qb('contact')->delete(1);
```

id column of contact table will delete a record.

ORDER BY
--------

[](#order-by)

```
$rows = Qb('contact')->asc('created_at')->toJson();
```

It will return a list of the contact table in ascending order of created\_at column.

```
$rows = Qb('contact')->desc('created_at')->asc('id')->toJson();
```

It will return a list of the contact table in descending order of created\_at column, in ascending order of id.

OFFSET, LIMIT
-------------

[](#offset-limit)

```
$rows = Qb('contact')->offset(10)->limit(5)->toJson();
```

You get 5 from 10 th in the list of contact table.

PDO object acquisition
----------------------

[](#pdo-object-acquisition)

```
$db = Qb('contact')->db();
```

You get the raw PDO object. Please, for example, when you put the transaction.

Option when connecting
----------------------

[](#option-when-connecting)

```
$options = [
  // Primary key
  'primary_key' => 'id',
  // ERRMODE
  'error_mode' => PDO::ERRMODE_EXCEPTION,
  // json_encode options
  'json_options' => JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT,
];
Qb::connect($dsn, $user, $pass, $options);
```

important point
===============

[](#important-point)

- 1 Program 1 connection with the assumption, is not suitable for large-scale programs.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

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

Recently: every ~21 days

Total

8

Last Release

3899d ago

### Community

Maintainers

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

---

Top Contributors

[![naga3](https://avatars.githubusercontent.com/u/5917968?v=4)](https://github.com/naga3 "naga3 (38 commits)")

---

Tags

pdoquery builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/naga3-qb/health.svg)

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

###  Alternatives

[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)[codesvault/howdy-qb

Mysql Query Builder for WordPress

371.2k1](/packages/codesvault-howdy-qb)

PHPackages © 2026

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