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

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

maleeshagimshan98/query-builder
===============================

10[1 issues](https://github.com/maleeshagimshan98/query-builder/issues)PHP

Since Mar 13Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

QueryBuilder
============

[](#querybuilder)

A tool to easily generate simple SQL queries. The built-in query builder for my ORM project [Infinite-Simple-ORM](https://github.com/maleeshagimshan98/infinite-simple-orm)

About
-----

[](#about)

The QueryBuilder is a PHP class that provides a set of methods for building SQL queries. This class supports building queries for CRUD Operations as well as adding conditions, limits, and offsets to the queries. Additionally, the class supports joining tables and ordering and grouping data.

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

[](#installation)

To install the package, add the package to composer.json and update.

```
"require": {
        "maleeshagimshan98/query-builder": "1.0.*"
    }

```

run following command :

`php composer.phar update`

Getting Started
---------------

[](#getting-started)

To get started, add this file to your project folder,

```
use Infinite\SimpleOrm\Query\QueryBuilder;

$builder = new QueryBuilder();

```

Here are key methods of the class:

- `from(string $table)` : Sets the table to select data from.
- `select(array $columns = null)` : Adds columns to select data from. If no columns are specified, all columns are selected.
- `where(array $condition)` : Adds a where condition to the query.
- `leftJoin(string $tableName, array $condition)` : Adds a left join with another table.
- `orderBy(string $column, string $type = "ASC")` : Adds an order by clause to the query.
- `limit(string $limit, string $offset)` : Sets the limit and offset of the result.
- `insert(string $table, array $values)` : Builds an insert query.
- `update(string $table, array $values, array $condition = [])` : Builds an update query.
- `delete(string $table, array $condition = [])` : Builds a delete query.

SELECT
------

[](#select)

select data from the users table, the following code can be used:

```
$builder = new QueryBuilder();
$builder->from('users');
$builder->select(['id', 'name', 'email']);
$query = $builder->sql();

```

SELECT with WHERE (Only uses "=")
---------------------------------

[](#select-with-where-only-uses-)

Select data with `WHERE` condition. Compares the array's key and value using "=" operator.

Syntax : `where([...['column_name' => 'value_evaluated']])`

```
$builder->from('users');
$builder->select(['id', 'name', 'email'])->where(['id' => '123','name' => "'abc'"])
$query = $builder->sql(); //... returns the generated sql query

```

SELECT with WHERE (Use comparison operators)
--------------------------------------------

[](#select-with-where-use-comparison-operators)

Select data with `WHERE` condition, use any comparison operators (=, &gt;, &lt;, etc.)

syntax : `where([.., [..], ['column_name','comparison_operator', 'value_evaluated']])`

```
$builder->from('users');
$builder->select(['id', 'name', 'email'])->where([['id','=','00002'],['name','=',"'aaaa'"]]);
$query = $builder->sql();

```

LEFT JOIN
---------

[](#left-join)

Select data and left join another table

```
$builder->from('users');
$builder->select(['id', 'name', 'email'])->leftJoin('products',[['product.user_id', '=', 'users.id'],['product.type','=','electronic']]);
$query = $builder->sql();

```

### INSERT

[](#insert)

To insert data into the users table, the following code can be used:

```
$builder = new QueryBuilder();
$builder->insert('users', ['name' => 'John Doe', 'email' => 'john.doe@example.com']);
$query = $builder->sql();

```

This code will generate a SQL query to insert a new row into the users table with the name 'John Doe' and the email ''.

### UPDATE

[](#update)

To update data in the users table, the following code can be used:

```
$builder = new QueryBuilder();
$builder->update('users', ['name' => 'John Doe', 'email' => 'john.doe@example.com']);
$query = $builder->sql();

```

### DELETE

[](#delete)

To delete data in the users table, the following code can be used:

```
$builder = new QueryBuilder();
$builder->delete('users', ['name' => 'John Doe', 'email' => 'john.doe@example.com']);
$query = $builder->sql();

```

Overall, the QueryBuilder provides a convenient and flexible way to build SQL queries in PHP code.

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

[](#contributing)

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
3. Commit your Changes (git commit -m 'Add some AmazingFeature')
4. Push to the Branch (git push origin feature/AmazingFeature)
5. Open a Pull Request

Licence
-------

[](#licence)

Distributed under the MIT License

Contact
-------

[](#contact)

- name - Maleesha Gimshan
- email - ()

###  Health Score

8

—

LowBetter than 0% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ef6248611a83544c720c6fa6a1298bf5d4cd5fdb0914fb7a01fd27f266ecf9b?d=identicon)[maleesha98](/maintainers/maleesha98)

---

Tags

phpqueryquery-builderquerybuildersql

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/maleeshagimshan98-query-builder/health.svg)](https://phpackages.com/packages/maleeshagimshan98-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)
