2017 © Pedro Peláez
 

library miner

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

image

ulue/miner

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

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 56 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

Miner

Latest Stable Version, (*1)

forked from https://github.com/jstayton/Miner, (*2)

A dead simple PHP class for building SQL statements. No manual string concatenation necessary., (*3)

Developed by Justin Stayton while at Monk Development., (*4)

Requirements

  • PHP > 7.0.0

Installation

Composer

The recommended installation method is through Composer, a dependency manager for PHP., (*5)

In command line:, (*6)

composer require phpcom-lab/miner

Or, just add phpcom-lab/miner to your project's composer.json file:, (*7)

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

More details can be found over at Packagist., (*8)

Getting Started

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

$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,, (*10)

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

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

$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:, (*12)

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

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

$PDOStatement = $miner->execute();

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

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

or after, (*15)

$miner->setPdoConnection($PDO);

Usage

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:, (*16)

$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 HIGH_PRIORITY shows
SET network_id = 13,
    name = 'Freaks & Geeks',
    air_day = 'Tuesday'

With Miner:, (*17)

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

REPLACE

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

With Miner:, (*18)

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

UPDATE

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

With Miner:, (*19)

$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
FROM shows
WHERE show_id IN (12, 15, 20)
LIMIT 3

With Miner:, (*20)

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

Methods

SELECT

INSERT

REPLACE

UPDATE

DELETE

OPTIONS

SET / VALUES

FROM

WHERE

GROUP BY

HAVING

ORDER BY

LIMIT

Statement

Connection

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., (*21)

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.

The Versions

05/05 2018

dev-master

9999999-dev https://github.com/ulue/Miner

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

  Sources   Download

MIT

The Requires

  • php >7.0.0

 

sql postgresql crud query pdo mysql sqlite statement sequel statements

05/05 2018

v1.0.1

1.0.1.0 https://github.com/ulue/Miner

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

  Sources   Download

MIT

The Requires

  • php >7.0.0

 

sql postgresql crud query pdo mysql sqlite statement sequel statements

04/05 2018

v1.0.0

1.0.0.0 https://github.com/ulue/Miner

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

  Sources   Download

MIT

The Requires

  • php >7.0

 

The Development Requires

sql postgresql crud query pdo mysql sqlite statement sequel statements

30/03 2014

v0.10.0

0.10.0.0 https://github.com/jstayton/Miner

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

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

The Development Requires

sql postgresql update crud query delete select pdo mysql sqlite querybuilder insert statement queries sequel statements

08/12 2013

v0.9.4

0.9.4.0 https://github.com/jstayton/Miner

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

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

The Development Requires

sql postgresql update crud query delete select pdo mysql sqlite querybuilder insert statement queries sequel statements

18/11 2013

v0.9.3

0.9.3.0 https://github.com/jstayton/Miner

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

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

sql postgresql update crud query delete select pdo mysql sqlite querybuilder insert statement queries sequel statements

29/09 2013

v0.9.2

0.9.2.0 https://github.com/jstayton/Miner

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

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

sql postgresql update crud query delete select pdo mysql sqlite querybuilder insert statement queries sequel statements

04/10 2012

v0.9.1

0.9.1.0 https://github.com/jstayton/Miner

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

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

sql postgresql update crud query delete select pdo mysql sqlite querybuilder insert statement queries sequel statements

17/09 2012

v0.9.0

0.9.0.0 https://github.com/jstayton/Miner

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

  Sources   Download

MIT

The Requires

  • php >=5.1.0

 

sql postgresql update crud query delete select pdo mysql sqlite querybuilder insert statement queries sequel statements