PHPackages                             ulue/miner - 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. ulue/miner

Abandoned → [phpcom-lab/miner](/?search=phpcom-lab%2Fminer)Library[Database &amp; ORM](/categories/database)

ulue/miner
==========

A dead simple PHP class for building SQL statements. No manual string concatenation necessary.

v1.0.1(8y ago)113MITPHPPHP &gt;7.0.0

Since Sep 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/phppkg/miner)[ Packagist](https://packagist.org/packages/ulue/miner)[ Docs](https://github.com/ulue/Miner)[ RSS](/packages/ulue-miner/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (9)Used By (0)

Miner
=====

[](#miner)

[![Latest Stable Version](https://camo.githubusercontent.com/98d97e4e9133e08fa0f166ef02ada0ce4e8b6243d10da21002454a83a3aa943b/68747470733a2f2f706f7365722e707567782e6f72672f706870636f6d2d6c61622f6d696e65722f762f737461626c652e706e67)](https://packagist.org/packages/phpcom-lab/miner)

> forked from

A dead simple PHP class for building SQL statements. No manual string concatenation necessary.

Developed by [Justin Stayton](http://twitter.com/jstayton) while at [Monk Development](http://monkdev.com).

- [Documentation](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html)
- [Release Notes](https://github.com/phpcom-lab/miner/wiki/Release-Notes)

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

[](#requirements)

- PHP &gt; 7.0.0

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

[](#installation)

### Composer

[](#composer)

The recommended installation method is through [Composer](http://getcomposer.org/), a dependency manager for PHP.

In command line:

```
composer require phpcom-lab/miner
```

Or, just add `phpcom-lab/miner` to your project's `composer.json` file:

```
{
    "require": {
        "phpcom-lab/miner": "*"
    }
}
```

[More details](http://packagist.org/packages/phpcom-lab/miner) can be found over at [Packagist](http://packagist.org).

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

[](#getting-started)

Composing SQL with Miner is very similar to writing it by hand, as much of the syntax maps directly to methods:

```
$miner = Miner::create()
      ->select('*')
      ->from('shows')
      ->innerJoin('episodes', 'show_id')
      ->where('shows.network_id', 12)
      ->orderBy('episodes.aired_on', Miner::ORDER_BY_DESC)
      ->limit(20);
```

Now that the statement is built,

```
$miner->getSql(); // Or $miner->getStatement();
```

returns the full SQL string with placeholders (?), and

```
$miner->getBoundedParams(); // Or $miner->getPlaceholderValues();
```

returns the array of placeholder values that can then be passed to your database connection or abstraction layer of choice. Or, if you'd prefer it all at once, you can get the SQL string with values already safely quoted:

```
$miner->getSql(false); // Or $miner->getStatement(false);
```

If you're using PDO, however, Miner makes executing the statement even easier:

```
$PDOStatement = $miner->execute();
```

Miner works directly with your PDO connection, which can be passed during creation of the Miner object

```
$miner = Miner::create($PDO)
$miner = new Miner($PDO);
```

or after

```
$miner->setPdoConnection($PDO);
```

Usage
-----

[](#usage)

### SELECT

[](#select)

```
SELECT *
FROM shows
INNER JOIN episodes
  ON shows.show_id = episodes.show_id
WHERE shows.network_id = 12
ORDER BY episodes.aired_on DESC
LIMIT 20
```

With Miner:

```
$miner->select('*')
      ->from('shows')
      ->innerJoin('episodes', 'show_id')
      ->where('shows.network_id', 12)
      ->orderBy('episodes.aired_on', Miner::ORDER_BY_DESC)
      ->limit(20);
```

### INSERT

[](#insert)

```
INSERT HIGH_PRIORITY shows
SET network_id = 13,
    name = 'Freaks & Geeks',
    air_day = 'Tuesday'
```

With Miner:

```
$miner->insert('shows')
      ->option('HIGH_PRIORITY')
      ->set('network_id', 13)
      ->set('name', 'Freaks & Geeks')
      ->set('air_day', 'Tuesday');
```

### REPLACE

[](#replace)

```
REPLACE shows
SET network_id = 13,
    name = 'Freaks & Geeks',
    air_day = 'Monday'
```

With Miner:

```
$miner->replace('shows')
      ->set('network_id', 13)
      ->set('name', 'Freaks & Geeks')
      ->set('air_day', 'Monday');
```

### UPDATE

[](#update)

```
UPDATE episodes
SET aired_on = '2012-06-25'
WHERE show_id = 12
  OR (name = 'Girlfriends and Boyfriends' AND air_day != 'Monday')
```

With Miner:

```
$miner->update('episodes')
      ->set('aired_on', '2012-06-25')
      ->where('show_id', 12)
      ->openWhere(Miner::LOGICAL_OR)
          ->where('name', 'Girlfriends and Boyfriends')
          ->where('air_day', 'Monday', Miner::NOT_EQUALS)
      ->closeWhere();
```

### DELETE

[](#delete)

```
DELETE
FROM shows
WHERE show_id IN (12, 15, 20)
LIMIT 3
```

With Miner:

```
$miner->delete()
      ->from('shows')
      ->whereIn('show_id', array(12, 15, 20))
      ->limit(3);
```

Methods
-------

[](#methods)

- [\_\_construct](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method___construct)

### SELECT

[](#select-1)

- [select](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_select)
- [getSelect](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getSelect)
- [getSelectString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getSelectString)
- [mergeSelectInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeSelectInto)

### INSERT

[](#insert-1)

- [insert](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_insert)
- [getInsert](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getInsert)
- [getInsertString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getInsertString)
- [mergeInsertInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeInsertInto)

### REPLACE

[](#replace-1)

- [replace](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_replace)
- [getReplace](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getReplace)
- [getReplaceString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getReplaceString)
- [mergeReplaceInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeReplaceInto)

### UPDATE

[](#update-1)

- [update](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_update)
- [getUpdate](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getUpdate)
- [getUpdateString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getUpdateString)
- [mergeUpdateInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeUpdateInto)

### DELETE

[](#delete-1)

- [delete](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_delete)
- [getDeleteString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getDeleteString)
- [mergeDeleteInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeDeleteInto)

### OPTIONS

[](#options)

- [option](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_option)
- [calcFoundRows](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_calcFoundRows)
- [distinct](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_distinct)
- [getOptionsString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getOptionsString)
- [mergeOptionsInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeOptionsInto)

### SET / VALUES

[](#set--values)

- [set](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_set)
- [values](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_values)
- [getSetPlaceholderValues](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getSetPlaceholderValues)
- [getSetString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getSetString)
- [mergeSetInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeSetInto)

### FROM

[](#from)

- [from](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_from)
- [innerJoin](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_innerJoin)
- [leftJoin](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_leftJoin)
- [rightJoin](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_rightJoin)
- [join](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_join)
- [getFrom](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getFrom)
- [getFromAlias](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getFromAlias)
- [getFromString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getFromString)
- [getJoinString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getJoinString)
- [mergeFromInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeFromInto)
- [mergeJoinInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeJoinInto)

### WHERE

[](#where)

- [where](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_where)
- [andWhere](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_andWhere)
- [orWhere](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_orWhere)
- [whereIn](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_whereIn)
- [whereNotIn](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_whereNotIn)
- [whereBetween](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_whereBetween)
- [whereNotBetween](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_whereNotBetween)
- [openWhere](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_openWhere)
- [closeWhere](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_closeWhere)
- [getWherePlaceholderValues](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getWherePlaceholderValues)
- [getWhereString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getWhereString)
- [mergeWhereInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeWhereInto)

### GROUP BY

[](#group-by)

- [groupBy](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_groupBy)
- [getGroupByString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getGroupByString)
- [mergeGroupByInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeGroupByInto)

### HAVING

[](#having)

- [having](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_having)
- [andHaving](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_andHaving)
- [orHaving](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_orHaving)
- [havingIn](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_havingIn)
- [havingNotIn](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_havingNotIn)
- [havingBetween](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_havingBetween)
- [havingNotBetween](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_havingNotBetween)
- [openHaving](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_openHaving)
- [closeHaving](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_closeHaving)
- [getHavingPlaceholderValues](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getHavingPlaceholderValues)
- [getHavingString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getHavingString)
- [mergeHavingInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeHavingInto)

### ORDER BY

[](#order-by)

- [orderBy](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_orderBy)
- [getOrderByString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getOrderByString)
- [mergeOrderByInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeOrderByInto)

### LIMIT

[](#limit)

- [limit](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_limit)
- [getLimit](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getLimit)
- [getLimitOffset](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getLimitOffset)
- [getLimitString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getLimitString)

### Statement

[](#statement)

- [execute](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_execute)
- [getSql](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getSql)
- [getStatement](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getStatement)
- [getBoundedParams](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getBoundedParams)
- [getPlaceholderValues](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getPlaceholderValues)
- [isSelect](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_isSelect)
- [isInsert](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_isInsert)
- [isReplace](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_isReplace)
- [isUpdate](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_isUpdate)
- [isDelete](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_isDelete)
- [\_\_toString](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method___toString)
- [mergeInto](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_mergeInto)

### Connection

[](#connection)

- [setPdoConnection](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_setPdoConnection)
- [getPdoConnection](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getPdoConnection)
- [setAutoQuote](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_setAutoQuote)
- [getAutoQuote](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_getAutoQuote)
- [autoQuote](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_autoQuote)
- [quote](https://phpcom-lab.github.io/miner/classes/master/Miner/Miner.html#method_quote)

Feedback
--------

[](#feedback)

Please open an issue to request a feature or submit a bug report. Or even if you just want to provide some feedback, I'd love to hear. I'm also available on Twitter as [@jstayton](http://twitter.com/jstayton).

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

[](#contributing)

1. Fork it.
2. Create your feature branch (`git checkout -b my-new-feature`).
3. Commit your changes (`git commit -am 'Added some feature'`).
4. Push to the branch (`git push origin my-new-feature`).
5. Create a new Pull Request.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~293 days

Recently: every ~407 days

Total

8

Last Release

2930d ago

Major Versions

v0.10.0 → v1.0.02018-05-04

PHP version history (3 changes)v0.9.0PHP &gt;=5.1.0

v1.0.0PHP &gt;7.0

v1.0.1PHP &gt;7.0.0

### Community

Maintainers

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

---

Top Contributors

[![jstayton](https://avatars.githubusercontent.com/u/98357?v=4)](https://github.com/jstayton "jstayton (60 commits)")[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (9 commits)")[![detook](https://avatars.githubusercontent.com/u/853431?v=4)](https://github.com/detook "detook (1 commits)")

---

Tags

mysqlsqlitepostgresqlsqlpdoquerycrudstatementsequelstatements

### Embed Badge

![Health badge](/badges/ulue-miner/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)[jv2222/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

87311.3k2](/packages/jv2222-ezsql)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41249.0k7](/packages/atlas-query)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41234.1k4](/packages/aura-sqlschema)

PHPackages © 2026

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