PHPackages                             midorikocak/querymaker - 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. midorikocak/querymaker

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

midorikocak/querymaker
======================

QueryMaker is a little library that helps you create simple PDO queries

v1.4.7(6y ago)1630512MITPHPPHP ~7.4

Since Jan 23Pushed 6y ago1 watchersCompare

[ Source](https://github.com/midorikocak/querymaker)[ Packagist](https://packagist.org/packages/midorikocak/querymaker)[ Docs](https://github.com/midorikocak/querymaker)[ RSS](/packages/midorikocak-querymaker/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (2)

querymaker
==========

[](#querymaker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bdb3e1a8c8673619e40e8ecd742f2930475b0de920bcee6c30bc4b106ccd9488/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d69646f72696b6f63616b2f71756572796d616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/midorikocak/querymaker)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/54541c5e496872614f72e4af2da1546a76963d468bc83bcbb0fa8783ffd01cc1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d69646f72696b6f63616b2f71756572796d616b65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/midorikocak/querymaker)[![Coverage Status](https://camo.githubusercontent.com/575a50704d22e19d13e99666932e5da641617bda1e31c9065b591a0570cd8eb7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d69646f72696b6f63616b2f71756572796d616b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/midorikocak/querymaker/code-structure)[![Quality Score](https://camo.githubusercontent.com/3e82ef65b9ce60de933677885a3810021e143d3108a0d7a2210a8d2c489b9caf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d69646f72696b6f63616b2f71756572796d616b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/midorikocak/querymaker)[![Total Downloads](https://camo.githubusercontent.com/e92f9db71fe2bde6c74580cafc8062dbd54a8d935389e4d197e371b6e557dd9e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d69646f72696b6f63616b2f71756572796d616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/midorikocak/querymaker)

This small library, allows you to create simple SQL queries to use with PDO easily. Just using methods with simple db command names, you can create seamless statements and key value array to use in execution.

Motivation
----------

[](#motivation)

When using PDO, writing queries are prone to syntax and parameter errors. To prevent them in simple queries you can use this library.

Requirements
------------

[](#requirements)

Strictly requires PHP 7.4.

Install
-------

[](#install)

Via Composer

```
$ composer require midorikocak/querymaker
```

Usage
-----

[](#usage)

There are starter methods to create a query, such as `SELECT` and `UPDATE`.

### Select

[](#select)

```
$queryMaker = new QueryMaker();
$queryMaker->select('users');
echo $queryMaker->getQuery();
```

The above example will output:

```
SELECT * FROM users
```

### Select with fields

[](#select-with-fields)

Fields to select can be specified as well:

```
$queryMaker = new QueryMaker();
$queryMaker->select('users', ['id', 'email']);
echo $queryMaker->getQuery();
```

The above example will output:

```
SELECT id, email FROM users
```

### Fields with different operators

[](#fields-with-different-operators)

Field values can include operators, such as: `=`,`>`, `select('users', ['id', 'email'])->where('id', '3', '>=');
echo $queryMaker->getQuery();
echo $queryMaker->getStatement();
```

The above example will output:

```
SELECT id, email FROM users WHERE id>='3'
SELECT id, email FROM users WHERE id>=:id'
```

### Delete

[](#delete)

```
$queryMaker = new QueryMaker();
$queryMaker->delete('users');
echo $queryMaker->getQuery();
```

The above example will output:

```
DELETE FROM users
```

### Where

[](#where)

To specify `WHERE` clauase use `where($key, $value)` method.

```
$queryMaker = new QueryMaker();
$queryMaker->select('users', ['id', 'email'])->where('id', 3);
echo $queryMaker->getQuery();
echo $queryMaker->getStatement();
```

The above example will output:

```
SELECT id, email FROM users WHERE id='3'
SELECT id, email FROM users WHERE id=:id
```

### AND and OR

[](#and-and-or)

Contraints such as `AND` and `OR`, are methods as well. `and($key, $value)` and `or($key, $value)`

```
$queryMaker = new QueryMaker();
$queryMaker->select('users', ['id', 'email'])->where('id', 3)->and('email', 'mtkocak@gmail.com')->or('username', 'midori');
echo $queryMaker->getQuery();
echo $queryMaker->getStatement();
```

The above example will output:

```
SELECT id, email FROM users WHERE id='3' OR username='midori'
SELECT id, email FROM users WHERE id=:id OR username=:username
```

Multiple AND and OR clauses can have same field conditions.

```
$queryMaker = new QueryMaker();
$queryMaker->select('users', ['id', 'email'])->where('email', 'mtkocak@gmail.com')->and('id', '>3')->and('id', 'select('users', ['id', 'email'])->where('id', 3)->and('email', 'mtkocak@gmail.com')->or('username', 'midori');

$statement = $db->prepare($query->getStatement());

$statement->execute($query->getParams());
```

### Insert

[](#insert)

To specify `INSERT` operation, `insert()` method, expects a key value array.

```
$queryMaker = new QueryMaker();
$queryMaker->insert('users', ['email' => 'mtkocak@gmail.com', 'username' => 'midorikocak']);
echo $queryMaker->getQuery();
echo $queryMaker->getStatement();
```

The above example will output:

```
INSERT INTO users (email, username) VALUES ('mtkocak@gmail.com', 'midorikocak')
INSERT INTO users (email, username) VALUES (:email, :username)
```

### Update

[](#update)

To specify `UPDATE` operation, handy `update()` method, expects a key value array. All statement params are generated thoroughly.

```
$queryMaker = new QueryMaker();
$queryMaker->update('users', ['email' => 'mtkocak@gmail.com', 'username' => 'midorikocak'])->where('id', 3);
echo $queryMaker->getQuery();
echo $queryMaker->getStatement();
```

The above example will output:

```
UPDATE users SET email='mtkocak@gmail.com', username='midorikocak' WHERE id='3'
UPDATE users SET email=:email, username=:username WHERE id=:id
```

Warning
-------

[](#warning)

This library is for educational purposes. Use at your own risk. Exposing query values and using it would create security issues.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Midori Kocak](https://github.com/midorikocak)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

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

Total

15

Last Release

2301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/983c3c55c001768e4e31e784835671f27dcccd9158a77870ffbb8167896f88f1?d=identicon)[midorikocak](/maintainers/midorikocak)

---

Top Contributors

[![midorikocak](https://avatars.githubusercontent.com/u/545472?v=4)](https://github.com/midorikocak "midorikocak (34 commits)")

---

Tags

midorikocakquerymaker

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/midorikocak-querymaker/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/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)
