PHPackages                             offworks/overnight - 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. offworks/overnight

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

offworks/overnight
==================

Yet another simple and consistent pdo based php-mysql query builder

v1.0.1(6y ago)229MITPHP

Since Jun 15Pushed 6y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Overnight
=========

[](#overnight)

An overnightly simple and consistent PHP-mysql query builder based on PDO.

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

[](#installation)

##### Composer

[](#composer)

```
composer require offworks/overnight

```

##### Git clone

[](#git-clone)

```
git clone https://github.com/offworks/overnight

```

then, require the autoload from the location

```
require_once __DIR__.'/path/to/overnight/src/autoload.php';

```

Usage
-----

[](#usage)

#### Create connection

[](#create-connection)

```
$db = \Overnight\Connection::create('localhost', 'user', 'password', 'dbname');

```

### SELECT

[](#select)

##### WHERE

[](#where)

Get an array of records

```
$users = $db->table('user')
        ->where('created_at > ?', array(date('Y-m-d H:i:s'))
        ->execute()->all();

```

Get an associated key value single (first) record

```
$user = $db->from('user')
        ->select('name, email, birthdate')
        ->where('user_id = ?', array($userId))
        ->execute()->first();

```

*p/s : from() is an alias of table()*

Multiple wheres

```
$tickets = $db->from('ticket')
           ->where('available = ? AND used = ?', array(1, 0))
           ->where('expiry_date < ?', array('2020-10-10'))
           ->andWhere('seat_type = ?', array('single'))
           ->orWhere('master_ticket = ?', array(1))
           ->execute();

// will execute something like
SELECT * FROM ticket WHERE available = 1 AND used = 0 AND expiry_date < '2020-10-10' AND seat_type = 'single'

```

##### INNER JOIN

[](#inner-join)

```
$books = $db->from('book')
         ->innerJoin('author ON author.author_id = book.author_id')
         ->execute()->all();

```

##### LEFT JOIN

[](#left-join)

```
$users = $db->from('user')
         ->leftJoin('membership ON membership.user_id = user.user_id')
         ->execute()->all();

```

Parameterized join

```
$users = $db->from('book')
        ->innerJoin('author ON author.author_id = book.author_id AND author.is_alive = ?', array(1))
        ->execute()->all();

```

##### ORDER BY

[](#order-by)

```
$students = $db->from('student')
            ->where('is_alive = ?', array(1))
            ->orderBy('last_seen DESC')
            ->execute()->all();

```

##### GET RAW SQL

[](#get-raw-sql)

```
$sql = $db->from('news')
       ->innerJoin('editor ON news.editor_id = editor.editor_id')
       ->where('DATE(published_at) = ?', array(date('Y-m-d H:i:s')))
       ->orderBy('published_at DESC')
       ->getSql();

```

### INSERT

[](#insert)

```
$db->insert('user')->values(array(
    'name' => 'James',
    'like' => 'Foo cake',
    'birthdate' => '1977-05-09'
  ))->execute();

```

or

```
$db->insert('user', array(
    'name' => 'James',
    'like' => 'Foo cake',
    'birthdate' => '1977-05-09'
  ))->execute();

```

#### Last insert id

[](#last-insert-id)

```
$userId = $db->lastInsertId();

```

or

```
$userId = $db->insert('user')->values($values)->execute()->id();

```

### UPDATE

[](#update)

```
$db->update('book')
->where('book_id = ?', array($bookId))
->set(array('title' => 'the lost marble - first edition'))
->execute();

```

### DELETE

[](#delete)

```
$db->delete('author')
->where('author_id = ?', array($authorId))
->execute();

```

APIs
----

[](#apis)

#### General

[](#general)

```
$query->execute()
  getStatement()
$query->getSql()
$db->lastInsertId()
$db->execute(string $sql, array $values, array $params))
$db->getPdo()

```

#### Select

[](#select-1)

```
from(string $table) or table(string $table)
select(string|array $columns)
where(string $condition, array $values = array())
orWhere(string $condition, array $values = array())
orderBy(string $orderBy)
groupBy(string $groupBy)
innerJoin(string $condition, array $values = array())
leftJoin(string $condition, array $values = array())
rightJoin(string $condition, array $values = array())
limit(int $limit, int $offset = null)
having(string $condition, array $values = array())
execute()->all()
execute()->first()

```

#### Insert

[](#insert-1)

```
insert(string $table, array $values = array())
values(array $values)
execute()->id()

```

#### Update

[](#update-1)

```
update(string $table)
set(array $data)
where(string $condition, array $values = array())
orWhere(string $condition, array $values = array())

```

#### Delete

[](#delete-1)

```
delete(string $table)
where(string $condition, array $values = array())
orWhere(string $condition, array $values = array())

```

License
-------

[](#license)

[MIT](LICENSE.md)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Total

2

Last Release

2511d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6693955d4298b16620ee544b2e484dce692f383b326f23d5a26f435fcf666634?d=identicon)[eimihar](/maintainers/eimihar)

---

Top Contributors

[![eimihar](https://avatars.githubusercontent.com/u/5824953?v=4)](https://github.com/eimihar "eimihar (39 commits)")

---

Tags

builderdbalmysqlpdophpquerymysqlpdoquery builderphp mysql

### Embed Badge

![Health badge](/badges/offworks-overnight/health.svg)

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

###  Alternatives

[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)[codesvault/howdy-qb

Mysql Query Builder for WordPress

371.2k1](/packages/codesvault-howdy-qb)

PHPackages © 2026

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