PHPackages                             gin0115/pixie-wpdb - 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. gin0115/pixie-wpdb

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

gin0115/pixie-wpdb
==================

An adaptation of Pixie (created byusmanhalalit) for WordPress using WPDB over PDO.

0.0.3(4y ago)2302[5 PRs](https://github.com/gin0115/pixie-wpdb/pulls)MITPHPPHP &gt;=7.1.0

Since Jan 14Pushed 3y ago2 watchersCompare

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

READMEChangelog (6)Dependencies (12)Versions (35)Used By (0)

Pixie WPDB Query Builder for WordPress
======================================

[](#pixie-wpdb-query-builder-for-wordpress)

[![GitHub issues](https://camo.githubusercontent.com/67079919942c9579c05c3445d60670245c33e776d24dc8103c9a4ea9cbb78cea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f67696e303131352f70697869652d77706462)](https://github.com/gin0115/pixie-wpdb/releases)[![](https://github.com/gin0115/pixie-wpdb/workflows/GitHub_CI/badge.svg " ")](https://github.com/gin0115/pixie-wpdb/workflows/GitHub_CI/badge.svg)[![codecov](https://camo.githubusercontent.com/aeff9e2d6689ea7d1cc0b5b62864b0781f301cd44602416351063a965857dfa4/68747470733a2f2f636f6465636f762e696f2f67682f67696e303131352f70697869652d777064622f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d34794563654961534650)](https://codecov.io/gh/gin0115/pixie-wpdb)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/77bfd69a34f91f1e6ef559a176c0f6ef1e059905f12e92b72926bb892f4394a2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f67696e303131352f70697869652d777064622f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/gin0115/pixie-wpdb/?branch=master)[![GitHub issues](https://camo.githubusercontent.com/58661276731025d0d902ed8eccf91c948c1109531d272a3bc5d8eb8fd0712cc8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f67696e303131352f70697869652d77706462)](https://github.com/gin0115/pixie-wpdb/issues)![Open Source Love](https://camo.githubusercontent.com/2d4eac62d5f5830a5309100b88e0ecccb171aee1fbcd794149f4a580b0010c56/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f6d69742f6d69742e7376673f763d313032)

An expressive, query builder for WordPRess it can also be referred as a Database Abstraction Layer. Pixie WPDB supports WPDB ONLY and it takes care of query sanitization, table prefixing and many other things with a unified API.

> **Pixie WPDB** is an adaption of `pixie` originally written by [usmanhalalit](https://github.com/usmanhalalit). [Pixie](https://github.com/usmanhalalit/pixie) is no longer under active development.

Features
========

[](#features)

- [Fluent API](https://github.com/gin0115/pixie-wpdb/wiki/Query%20Methods)
- [Nested Queries](https://github.com/gin0115/pixie-wpdb/wiki/Sub%20&%20Nested%20Queries)
- [Multiple Connections](https://github.com/gin0115/pixie-wpdb/wiki/Home#setup-connection)
- [Sub Queries](https://github.com/gin0115/pixie-wpdb/wiki/Sub%20&%20Nested%20Queries)
- [JSON Support](https://github.com/gin0115/pixie-wpdb/wiki/Json%20Methods)
- [Model Hydration](https://github.com/gin0115/pixie-wpdb/wiki/Result%20Hydration)
- [Custom Alias Facade](https://github.com/gin0115/pixie-wpdb/wiki/Home#connection-alias)
- [Raw SQL Expressions](https://github.com/gin0115/pixie-wpdb/wiki/Bindings%20&%20Raw%20Expressions)
- [Value Type Binding](https://github.com/gin0115/pixie-wpdb/wiki/Bindings%20&%20Raw%20Expressions)
- [Transaction Support](https://github.com/gin0115/pixie-wpdb/wiki/Transactions)
- [Query Events](https://github.com/gin0115/pixie-wpdb/wiki/Query%20Events)

```
$thing = QB::table('someTable')->where('something','=', 'something else')->first();
```

Install
=======

[](#install)

Perquisites
-----------

[](#perquisites)

- WordPress 5.7+ (tested upto 5.9)
- PHP 7.1+ (includes support for PHP8)
- MySql 5.7+ or MariaDB 10.2+
- Composer (optional)

Using Composer
--------------

[](#using-composer)

The easiest way to include Pixie in your project is to use [composer](http://getcomposer.org/doc/00-intro.md#installation-nix).

```
composer require gin0115/pixie-wpdb
```

Static Loader
-------------

[](#static-loader)

If you are planning to just inlcude Pixie direct in your plugin, you can extract the `src` directory and add this to your `functions.php` or similar.

```
require_once '/path/to/src/loader.php';
```

> Each class is checked if already loaded, to avoid conflicts if used on multiple plugins.

Setup Connection
================

[](#setup-connection)

If you are only planning on having a single connection, you will only need to configure the connection once.

```
# Basic setup

// Access the global WPDB or a custom instance for additional tables.
global $wpdb;

// Configure the builder and/or internal WPDB instance
$connection_config = [Connection::PREFIX => 'gin0115_'];

// Give a *single* Alias
$builder_alias = 'Gin0115\\DB';

new Connection( $wpdb, $connection_config, $builder_alias );
```

This would then give access to an instance of the QueryBuilder using this connection, via the alias defined `Gin0115\DB`

```
$foos = Gin0115\DB::table('foo')->where('column', 'red')->get();
```

> Generated &amp; executed query :: "SELECT \* FROM gin0115\_foo WHERE column = 'red'; "

Connection Config
-----------------

[](#connection-config)

It is possible to configure the connection used by your instance of the query builder.

Values

KeyConstantValueDescriptionprefixConnection:: PREFIXSTRINGCustom table prefix (will ignore WPDB prefix)use\_wpdb\_prefixConnection:: USE\_WPDB\_PREFIXBOOLIf true will use WPDB prefix and ignore custom prefixclone\_wpdbConnection:: CLONE\_WPDBBOOLIf true, will clone WPDB to not use reference to the instance (usually the $GLOBAL)show\_errorsConnection:: SHOW\_ERRORSBOOLIf set to true will configure WPDB to show/hide errors```
$config = [
    Connection::PREFIX          => 'acme_',
    Connection::USE_WPDB_PREFIX => true,
    Connection::CLONE_WPDB      => true,
    Connection::SHOW_ERRORS     => false,
];
```

> [More details on the config](https://github.com/gin0115/pixie-wpdb/wiki#connection-config)

Connection Alias
----------------

[](#connection-alias)

When you create a connection:

```
new Connection($wpdb, $config, 'MyAlias');
```

`MyAlias` is the name for the class alias you want to use (like `MyAlias::table(...)` ), you can use whatever name (with Namespace also, `MyNamespace\\MyClass` ) you like or you may skip it if you don't need an alias. Alias gives you the ability to easily access the QueryBuilder class across your application.

Usage
=====

[](#usage)

Once a connection is created, the builder can be accessed either directly using the Alias Facade or by creating an instance.

Static Usage
------------

[](#static-usage)

The easiest way to use Pixie is to use the alias facade provided. This allows you to access a builder instance anywhere, much like WPDB.

```
// Create the connection early on.
$connection = new Connection($wpdb, $config, 'Alias');

// Insert some data to bar.
Alias::table('bar')->insert(['column'=>'value']);
```

None Static Usage
-----------------

[](#none-static-usage)

When not using an alias you can instantiate the QueryBuilder handler separately, helpful for Dependency Injection and Testing.

```
// Create connection and builder instance.
$connection = new Connection($wpdb, $config);
$qb = new QueryBuilderHandler($connection);

$query = $qb->table('my_table')->where('name', '=', 'Sana');
$results = $query->get();
```

`$connection` here is optional, if not given it will always associate itself to the first connection, but it can be useful when you have multiple database connections.

Credits
=======

[](#credits)

This package began as a fork of [Pixie](https://github.com/usmanhalalit/pixie) originally written by [usmanhalalit](https://github.com/usmanhalalit)A few features have been inspired by the [Pecee-pixie](https://github.com/skipperbent/pecee-pixie/) fork and continuation, especially the extended aggregate methods.

Changelog
---------

[](#changelog)

- 0.0.3 - More improvements to the `updateOrInsert()` method.
- 0.0.2 - Improvements to the `updateOrInsert()` method
- 0.0.1 - Various external and interal changes made to the initial code written by [Muhammad Usman](http://usman.it/)

---

If you find any typo then please edit and send a pull request.

© 2022 [Glynn Quelch](https://www.github.com/gin0115). Licensed under MIT license.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.5% 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 ~18 days

Total

6

Last Release

1494d ago

### Community

Maintainers

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

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (220 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

wordpressdatabasesqlquery builderwpdb

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gin0115-pixie-wpdb/health.svg)

```
[![Health](https://phpackages.com/badges/gin0115-pixie-wpdb/health.svg)](https://phpackages.com/packages/gin0115-pixie-wpdb)
```

###  Alternatives

[usmanhalalit/pixie

A lightweight, expressive, framework agnostic query builder for PHP.

6872.2M15](/packages/usmanhalalit-pixie)[foolz/sphinxql-query-builder

A PHP query builder for SphinxQL and ManticoreQL with MySQLi and PDO drivers.

3232.2M32](/packages/foolz-sphinxql-query-builder)[opis/database

A database abstraction layer over PDO, that provides a powerful and intuitive query builder, bundled with an easy to use schema builder

10184.2k3](/packages/opis-database)[friedolinfoerder/wp-activerecord

An ActiveRecord implementation for WordPress

237.2k](/packages/friedolinfoerder-wp-activerecord)

PHPackages © 2026

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