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

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

lucasmialichi/query-builder
===========================

A simple query builder

1.3.5(2y ago)11051MITPHP

Since Dec 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/lcmialichi/query-builder)[ Packagist](https://packagist.org/packages/lucasmialichi/query-builder)[ RSS](/packages/lucasmialichi-query-builder/feed)WikiDiscussions main Synced yesterday

READMEChangelog (8)DependenciesVersions (10)Used By (1)

**QueryBuilder**
================

[](#querybuilder)

A simple and complete query builder to add practicality to your project

---

**INDEX**
---------

[](#index)

- ***Instalation***
- ***Connection***
- ***Select statement***
    - ***More Examples***
    - ***Expressions***
- ***Insert statement***
- ***Update statement***
- ***Delete statement***

---

**Instalation**
---------------

[](#instalation)

```
composer require lucasmialichi/query-builder
```

**Connection:**
---------------

[](#connection)

---

```
// build connection ...
$qb = new QueryBuilder(
    new Connection(
        "127.0.0.1",  // host
        "root",       // user
        123,          // password
        "teste"       // db name
    )
);
```

---

**Select statement:**
---------------------

[](#select-statement)

```
$qb->select()->from('users')->where('id', '=', ':Id');
$qb->addParam(':Id', 1);
$result = $qb->execute(); //Instance of QueryBuilder/Connection/QueryResult
```

the example above converted to SQL:

```
SELECT * FROM  users where id = :Id
```

Methods for query result:

- fetchAll: fetch all result as an associative array
- fetchFunction: fetch each row implementing a userfunction
- fetchAssociative: fetch using iteration (Generator)
- count: count numbers of rows before fetch

**more examples:**
------------------

[](#more-examples)

**PHP:**

```
$qb->select([
    "id" => "identifier",
    "name" => "userName",
    "birth_date" => "birthDate"
])
->from('users', "u")
->join("address", "u.address_id = a.id", "a")
->where('id', '=', ':Id')
->orWhere("birth_date", ">", date("Y-m-d H:i:s"))
->limit(10)
->offset(1);
```

**SQL:**

```
SELECT id AS identifier, name AS userName, birth_date AS birthDate FROM users u INNER JOIN address a ON u.address_id = a.id WHERE ( id = :Id ) OR ( birth_date > 2023-12-18 14:30:43 ) LIMIT 10 OFFSET 1
```

---

**Expressions:**
----------------

[](#expressions)

There are two ways to instanciate expressions in this qb

staticly calling directly QueryBuilder class

```
$expression = QueryBuilder::Expr();
```

Or if you aready had initilized queryBuilder you can call it in any moment of the query

```
$qb->select()->from('users')->where(
    $qb->expr("id")->in([1,2,3])->or()->between(1,10)
);
```

You can also use expression in select statement, like:

```
$qb->select(
    $qb->expr()->caseWhen("id = 1", "0")
        ->when("id = 2", "1")
        ->else("2")
        ->end()
)->from('users');
```

---

**Insert statement**
--------------------

[](#insert-statement)

**PHP**

```
$qb->insert([
    "name" => "alfredo",
    "birth_date" => "1988-06-11"
])->into("users");
```

the values are automatically binded to the query as parameters

**SQL:**

```
INSERT INTO users (name, birth_date) VALUES ('alfredo', '1988-06-11')
```

---

**Update statement**
--------------------

[](#update-statement)

**PHP**

```
$qb->update([
    "name" => "alfredo",
    "birth_date" => "1988-06-11"
])->from("users")
  ->where("id", "=", ":userId")
  ->addParam(":userId", 2);
```

the values are automatically binded to the query as parameters

**SQL:**

```
UPDATE users SET name = 'alfredo', birth_date = '1988-06-11' WHERE id = :userId
```

---

**Delete statement**
--------------------

[](#delete-statement)

```
$qb->delete()->from("users")->where($qb->expr("id")->notBetween(1,5))
```

**SQL:**

```
DELETE FROM users WHERE (id not between 1 and 5)
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

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

Total

9

Last Release

861d ago

### Community

Maintainers

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

---

Top Contributors

[![lcmialichi](https://avatars.githubusercontent.com/u/85366936?v=4)](https://github.com/lcmialichi "lcmialichi (48 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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