PHPackages                             thehiredgun/mint - 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. thehiredgun/mint

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

thehiredgun/mint
================

A PDO-abstraction layer package

v1.1.0(8y ago)0321MITPHPPHP &gt;=7.0.0

Since Nov 8Pushed 8y agoCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

mint
====

[](#mint)

A crisp PDO-abstraction layer class

Installation:
-------------

[](#installation)

Recommended installation is via [Composer](https://getcomposer.org):

`composer require thehiredgun/mint`

or, add this to your composer.json:

```
"require": {
    ...,
    "thehiredgun/mint": "^1.0",
    ...
}

```

Quick-Start:
------------

[](#quick-start)

*mint* is here to provide a crisp, clean interface between application and database layers. It uses the PDO object you hand it, gathers some meta data for your database, then makes your life easier by giving you methods to do just about anything you need to do, with one line of PHP.

```
use TheHiredGun\Mint\Mint;
...

// Mint::__construct takes a PDO object as it's argument
$db = new Mint(new PDO($dsn, $username, $password));

```

### These first four methods are used when you write a query manually:

[](#these-first-four-methods-are-used-when-you-write-a-query-manually)

Each method returns the type of response you would typically want to receive when executing that type of query:

- select returns the array of rows resulting from your query
- selectOne returns the query result's first row
- update returns the $PDOStatement-&gt;rowCount(), which is the number of rows affected by your query
- delete also returns the $PDOStatement-&gt;rowCount()

Each of these methods takes a query as its first argument:

```
'UPDATE my_table SET token_one = :token_one, token_two = :token_two WHERE token_three = :token_three

```

And (optionally) as its second argument, an associative array of parameters:

```
[
    'token_one'   => $token_one_value,
    'token_two'   => $token_two_value,
    'token_three' => $token_three_value,
]

```

Mint *always* tokenizes your parameters (i.e. adds ':' to the index for each parameter), so though your *query* needs to be written with those tokens, your *array of parameters does not need to be*.

```
// returns an array of rows from books where books.author = 'Vladimir Nabokov'
$books = $db->select('SELECT * FROM books WHERE author = :author ORDER BY title ASC', [
    'author' => 'Vladimir Nabokov'
]);

// returns the first of the record(s) returned from the query
$bookId = $db->selectOne('SELECT * FROM books WHERE author = :author AND title = :title', [
    'title'  => 'Pale Fire',
    'author' => 'Vladimir Nabokov',
]);

// returns the number of affected rows from the query
$numAffectedRows = $db->update('UPDATE books SET author = :author WHERE title IN("Pale Fire", "Lolita")', [
    'author' => 'Vladimir Nabokov',
]);

// returns the number of affected rows from the query
$numAffectedRows = $db->delete('DELETE FROM books WHERE author = :author', [
    'author' => 'Vladimir Nabokov'
]);

```

### Shorthand Methods

[](#shorthand-methods)

There are a few shorthand methods which make a lot of commonly-executed operations go much more quickly:

- selectOneById($table, $primaryKey) returns the record from $table with the $primaryKey
- deleteOneById($table, $primaryKey) deletes the record from $table with the $primaryKey, and returns the number of affected rows
- insertOne($table, $params) writes, executes and binds a parameterized INSERT query for $table (based on the meta data Mint gathered and the indexes in your $params), and returns the primary key of the new record. insertOne() *only* adds a column name, token, and parameter *if and when* the table has the column *and* your $params has an index for that column.
- updateOne($table, $params, $primaryKey) writes, executes, and binds a parameterized UPDATE query for a the $table and record (with $primaryKey), only adding columns, tokens, and parameters *if and when* the table has the column *and* your $params has an index for that column.

```
// returns the row from books where books' primary key = $bookId
$db->selectOneById('books', $bookId);

// returns num of deleted rows (i.e. 1)
$db->deleteOneById('books', $bookId);

// returns the primary key for the record you just inserted
$bookId = $db->insertOne('books', ['author' => 'Vladimir Nabokov', 'title' => 'Pale Fire']);

// returns num affected rows (usually 1)
$db->updateOne('books', ['author' => 'Vladimir Nabokov'], $bookId);

```

### Hints, Best Practices, &amp; Limitations

[](#hints-best-practices--limitations)

- At present, *mint* works with MySQL and SQLite3. It can be extended to allow for the use of other PDO Drivers. (Please submit a Pull Request if you do!!!)
- Generally speaking you want to configure your PDO error mode to 'Exception: `$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION)`
- Mint binds *named parameters*, using the format ':' + column\_name, so...:
- If you are writing a query manually, you'll want to write the tokens with a ':' preceding them, and the indexes of the parameters you supply should match those tokens (Mint will automatically make sure each token has a ':')
- If you are using a shorthand method like insertOne or updateOne, Mint will automatically match your parameters with the columns of the table, and throw out any which do not match. No need to write a query, match parameters, or add ':' to your indexes. Mint will *only* add columns and values to the query if they are included in you array of parameters.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

2

Last Release

3102d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ca5f709df7ca86d44b039a8b014727eeaaa72a0a776fda22a1f0e63b0bd546d?d=identicon)[thehiredgun](/maintainers/thehiredgun)

---

Tags

phpmysqlsqlitepdosqlite3

### Embed Badge

![Health badge](/badges/thehiredgun-mint/health.svg)

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

###  Alternatives

[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)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)[delight-im/db

Safe and convenient SQL database access in a driver-agnostic way

49156.8k7](/packages/delight-im-db)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1814.6k11](/packages/popphp-pop-db)[eftec/pdoone

Minimaist procedural PDO wrapper library

1105.9k9](/packages/eftec-pdoone)

PHPackages © 2026

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