PHPackages                             jaredtking/jaqb - 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. jaredtking/jaqb

Abandoned → [jaqb/jaqb](/?search=jaqb%2Fjaqb)Library[Database &amp; ORM](/categories/database)

jaredtking/jaqb
===============

Just Another Query Builder built on PDO

1.6(5y ago)12.7k[1 issues](https://github.com/jaredtking/jaqb/issues)MITPHPPHP &gt;=5.6.0CI failing

Since Feb 1Pushed 5y ago1 watchersCompare

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

READMEChangelog (9)Dependencies (4)Versions (10)Used By (0)

JAQB
====

[](#jaqb)

[![Latest Stable Version](https://camo.githubusercontent.com/af0b0486acf781db01248a311ef6147f24e8877210ab69d51e9a486ed2c9a68c/68747470733a2f2f706f7365722e707567782e6f72672f6a6171622f6a6171622f762f737461626c652e7376673f7374796c653d666c6174)](https://packagist.org/packages/jaqb/jaqb)[![Software License](https://camo.githubusercontent.com/f251623e510f5909f16ae3f4e6e548dac11340b9fde1a99be26b015b39272c00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c6174)](LICENSE)[![Build Status](https://camo.githubusercontent.com/e1c72b5e8ef46188af563d11b3756e6e23cd9b703964a46cee568836ad17e1f5/68747470733a2f2f7472617669732d63692e6f72672f6a61726564746b696e672f6a6171622e7376673f6272616e63683d6d6173746572267374796c653d666c6174)](https://travis-ci.org/jaredtking/jaqb)[![Coverage Status](https://camo.githubusercontent.com/1f5d778ce685f0374ced9fdc95e252d175805c1eef80ee6cecedf0ca7942a225/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6a61726564746b696e672f6a6171622f62616467652e7376673f7374796c653d666c6174)](https://coveralls.io/r/jaredtking/jaqb)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7ab997709024769677d98e96b7092c7e39dc7d4e158f6655d8783489c1ac574a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61726564746b696e672f6a6171622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jaredtking/jaqb/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/0f274be30da4e4faae55747c88848486c30b495fc7e289d5837c31272c124c3a/68747470733a2f2f706f7365722e707567782e6f72672f6a6171622f6a6171622f646f776e6c6f6164732e7376673f7374796c653d666c6174)](https://packagist.org/packages/jaqb/jaqb)

JAQB: Just Another Query Builder for PHP (pronounced "jacob")

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

[](#requirements)

- PHP 5.6+, PHP 7+
- [PDO](http://php.net/pdo)

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

[](#installation)

The easiest way to install JAQB is with [composer](http://getcomposer.org):

```
composer require jaqb/jaqb

```

Configuration
-------------

[](#configuration)

The connection manager accepts an array of connection configurations. With the connection manager you can conveniently manage one or more database connections. Connections are referenced by a unique ID in the configuration.

```
use JAQB\ConnectionManager;

$config = [
    'main' => [
        'type' => 'mysql',
        'host' => 'localhost',
        'name' => 'dbname'
        'username' => 'myuser',
        'password' => 'mypassword',
        'options' => [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ]
    ],
    'sqlite' => [
        'dsn' => 'sqlite:mydb.sqlite'
    ]
];

$manager = new ConnectionManager($config);
```

### Supplying an existing PDO object

[](#supplying-an-existing-pdo-object)

You can also manually add existing PDO connections.

```
use JAQB\ConnectionManager;
use JAQB\QueryBuilder;

$pdo = new PDO('...');
$connection = new QueryBuilder($pdo);
$manager = new ConnectionManager();
$manager->add('users', $connection);
```

Usage
-----

[](#usage)

### Retrieving a connection

[](#retrieving-a-connection)

You can retrieve a connection by calling `get()` on the connection manager with the ID of the connection.

```
$db = $manager->get('main');
```

If there is only one connection then you can also get it as the default.

```
$db = $manager->getDefault();
```

### Select Query

[](#select-query)

```
$db->select('*')
   ->from('Movies')
   ->join('Directors', 'Directors.id = Movies.director_id')
   ->where('Directors.name', 'Quentin Tarantino')
   ->between('year', 1990, 2015)
   ->groupBy('category')
   ->having('rating', 4.5, '>')
   ->orderBy('rating', 'DESC')
   ->limit(100, 10)
   ->all();
```

### Insert Query

[](#insert-query)

```
$db->insert(['name' => 'Catcher in the Rye', 'author' => 'JD Salinger'])
   ->into('Books')
   ->execute();
```

### Update Query

[](#update-query)

```
$db->update('Users')
   ->where('uid', 10)
   ->values(['first_name' => 'JAQB', 'website' => 'example.com'])
   ->orderBy('uid', 'ASC')
   ->limit(100)
   ->execute();
```

### Delete Query

[](#delete-query)

```
$db->delete('Users')
   ->where('last_login', strtotime('-1 year'), '
