PHPackages                             co0lc0der/simple-query-builder - 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. co0lc0der/simple-query-builder

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

co0lc0der/simple-query-builder
==============================

A small easy-to-use php component for working with a database by PDO. It provides some public methods to manipulate data. Each SQL query is prepared and safe.

v0.4.1(1y ago)4311MITPHPPHP &gt;=7.4

Since Oct 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/co0lc0der/simple-query-builder-php)[ Packagist](https://packagist.org/packages/co0lc0der/simple-query-builder)[ RSS](/packages/co0lc0der-simple-query-builder/feed)WikiDiscussions main Synced 5d ago

READMEChangelog (8)Dependencies (1)Versions (8)Used By (0)

QueryBuilder php component
==========================

[](#querybuilder-php-component)

[![Latest Version](https://camo.githubusercontent.com/854f70ca53b88f7c7d069adf0826efc0183abe933f6b41685da79e1d934ef62d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f636f306c63306465722f73696d706c652d71756572792d6275696c6465722d7068703f7374796c653d666c61742d737175617265)](https://github.com/co0lc0der/simple-query-builder-php/release)[![GitHub repo size](https://camo.githubusercontent.com/5a5cefadaef6af66801cbe0091d8247887e03bcd99a15bb62bb7ed0c81fa03e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f636f306c63306465722f73696d706c652d71756572792d6275696c6465722d7068703f636f6c6f723d6f72616e6765266c6162656c3d73697a65267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/5a5cefadaef6af66801cbe0091d8247887e03bcd99a15bb62bb7ed0c81fa03e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f636f306c63306465722f73696d706c652d71756572792d6275696c6465722d7068703f636f6c6f723d6f72616e6765266c6162656c3d73697a65267374796c653d666c61742d737175617265)[![Packagist Downloads](https://camo.githubusercontent.com/756188377e0a091715c150cf454c0be513213ec6fe198d24ad98e771c0090c0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f306c63306465722f73696d706c652d71756572792d6275696c6465723f636f6c6f723d79656c6c6f77267374796c653d666c61742d737175617265)](https://packagist.org/packages/co0lc0der/simple-query-builder)[![GitHub license](https://camo.githubusercontent.com/1d5115cef86615b5666a4bd89ad3978711f75656ddff65d7781d4d8d9ede8755/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f306c63306465722f73696d706c652d71756572792d6275696c6465722d7068703f7374796c653d666c61742d737175617265)](https://github.com/co0lc0der/simple-query-builder-php/blob/main/LICENSE.md)[![Packagist PHP Version Support](https://camo.githubusercontent.com/c304116d1627fc3fa62b8bc6ff38178044315e13be7edb11b1e612460a73d41c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f306c63306465722f73696d706c652d71756572792d6275696c6465723f636f6c6f723d383939336265267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/c304116d1627fc3fa62b8bc6ff38178044315e13be7edb11b1e612460a73d41c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f306c63306465722f73696d706c652d71756572792d6275696c6465723f636f6c6f723d383939336265267374796c653d666c61742d737175617265)

This is a small easy-to-use PHP component for working with a database by PDO. It provides some public methods to compose SQL queries and manipulate data. Each SQL query is prepared and safe. QueryBuilder fetches data to *arrays* by default. At present time the component supports MySQL and SQLite (file or memory).

**PAY ATTENTION! v0.2 and v0.3+ are incompatible.**

Contributing
------------

[](#contributing)

Bug reports and/or pull requests are welcome

License
-------

[](#license)

The package is available as open source under the terms of the [MIT license](https://github.com/co0lc0der/simple-query-builder-php/blob/main/LICENSE.md)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require co0lc0der/simple-query-builder
```

or add

```
"co0lc0der/simple-query-builder": "*"
```

to the `require section` of your `composer.json` file.

How to use
----------

[](#how-to-use)

### Edit `config.php` and set the parameters up. Choose DB driver, DB name etc

[](#edit-configphp-and-set-the-parameters-up-choose-db-driver-db-name-etc)

```
$config = require_once __DIR__ . '/config.php';
```

### Use composer autoloader

[](#use-composer-autoloader)

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

use co0lc0der\QueryBuilder\Connection;
use co0lc0der\QueryBuilder\QueryBuilder;
```

### Init `QueryBuilder` with `Connection::make()`

[](#init-querybuilder-with-connectionmake)

```
$query = new QueryBuilder(Connection::make($config['database'])); // $printErrors = false

// for printing errors (since 0.3.6)
$query = new QueryBuilder(Connection::make($config['database']), true)
```

### Usage examples

[](#usage-examples)

#### Select all rows from a table

[](#select-all-rows-from-a-table)

```
$results = $query->select('users')->all();
```

Result query

```
SELECT * FROM `users`;
```

#### Select rows with two conditions

[](#select-rows-with-two-conditions)

```
$results = $query->select('users')->where([
  ['id', '>', 1],
  'and',
  ['group_id', 2],
])->all();
```

Result query

```
SELECT * FROM `users` WHERE (`id` > 1) AND (`group_id` = 2);
```

#### Update a row

[](#update-a-row)

```
$query->update('posts', ['status' => 'published'])
        ->where([['YEAR(`updated_at`)', '>', 2020]])
        ->go();
```

Result query

```
UPDATE `posts` SET `status` = 'published'
WHERE (YEAR(`updated_at`) > 2020);
```

More examples you can find in [documentation](https://github.com/co0lc0der/simple-query-builder-php/blob/main/docs/index.md) or tests.

ToDo
----

[](#todo)

I'm going to add the next features into future versions

- write more unit testes
- add subqueries for QueryBuilder
- add `BETWEEN`
- add `WHERE EXISTS`
- add TableBuilder class (for beginning `CREATE TABLE`, move `$query->drop()` and `$query->truncate()` into it)
- add PostgreSQL support
- add `WITH`
- and probably something more

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance42

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

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

Total

7

Last Release

466d ago

PHP version history (3 changes)v0.2PHP &gt;=7.1

v0.3PHP &gt;=7.3

v0.3.4PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![co0lc0der](https://avatars.githubusercontent.com/u/38027849?v=4)](https://github.com/co0lc0der "co0lc0der (125 commits)")

---

Tags

databasemysqlpdopdo-phpphpphp-oopquery-buildersqlsqlite

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/co0lc0der-simple-query-builder/health.svg)

```
[![Health](https://phpackages.com/badges/co0lc0der-simple-query-builder/health.svg)](https://phpackages.com/packages/co0lc0der-simple-query-builder)
```

###  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)
