PHPackages                             wpdiggerstudio/wpzylos-database - 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. wpdiggerstudio/wpzylos-database

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

wpdiggerstudio/wpzylos-database
===============================

Safe wpdb wrapper with query builder for WPZylos framework

v1.0.0(5mo ago)02785MITPHPPHP ^8.0CI failing

Since Feb 1Pushed 2w agoCompare

[ Source](https://github.com/WPDiggerStudio/wpzylos-database)[ Packagist](https://packagist.org/packages/wpdiggerstudio/wpzylos-database)[ Docs](https://github.com/WPDiggerStudio/wpzylos-database)[ Fund](https://www.paypal.com/donate/?hosted_button_id=66U4L3HG4TLCC)[ RSS](/packages/wpdiggerstudio-wpzylos-database/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (5)

WPZylos Database
================

[](#wpzylos-database)

[![PHP Version](https://camo.githubusercontent.com/911a83e2aa6fe73660ab613629a95c76622bf03049a7344e80c5ea72d4ef9c7d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e302d626c7565)](https://php.net)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)[![GitHub](https://camo.githubusercontent.com/dbe820b98864e115173c422b9472b725cfa678bee03b66ff2c453dad95a3d20b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4769744875622d575044696767657253747564696f2d3138313731373f6c6f676f3d676974687562)](https://github.com/WPDiggerStudio/wpzylos-database)

Safe `$wpdb` wrapper with fluent query builder for the WPZylos framework.

📖 **[Full Documentation](https://wpzylos.com)** | 🐛 **[Report Issues](https://github.com/WPDiggerStudio/wpzylos-database/issues)**

---

✨ Features
----------

[](#-features)

- **Connection Class** — Plugin-scoped `$wpdb` wrapper with 21 public methods
- **Query Builder** — Fluent chainable interface for SELECT, INSERT, UPDATE, DELETE
- **Automatic Preparation** — All queries use `$wpdb->prepare()` internally
- **Plugin-Scoped Table Names** — Automatic prefix handling via `ContextInterface`
- **Transaction Support** — Automatic and manual transaction management with rollback
- **CRUD Convenience** — `find()`, `insertGetId()`, and direct table methods
- **Error Inspection** — `hasError()`, `lastError()`, `rowsAffected()`
- **Raw Query Access** — `query()`, `getRow()`, `getResults()`, `getVar()`

---

📋 Requirements
--------------

[](#-requirements)

RequirementVersionPHP^8.0WordPress6.0+---

🚀 Installation
--------------

[](#-installation)

```
composer require wpdiggerstudio/wpzylos-database
```

---

⚙️ Service Provider Registration
--------------------------------

[](#️-service-provider-registration)

Register `DatabaseServiceProvider` in your plugin's service providers:

```
use WPZylos\Framework\Database\DatabaseServiceProvider;

// In your plugin's boot configuration
'providers' => [
    DatabaseServiceProvider::class,
],
```

This registers two singleton bindings:

BindingResolves To`Connection::class``Connection` instance`'db'`Same `Connection` instance---

📖 Quick Start
-------------

[](#-quick-start)

```
use WPZylos\Framework\Database\Connection;

// Resolve from container
$db = $app->make(Connection::class);
// or
$db = $app->make('db');

// Fluent queries via QueryBuilder
$users = $db->table('users')->get();
$user  = $db->table('users')->where('id', 1)->first();
```

---

🏗️ Core Usage
-------------

[](#️-core-usage)

### Select Queries

[](#select-queries)

```
// Get all records
$users = $db->table('users')->get();

// Get first record
$user = $db->table('users')->where('email', $email)->first();

// Select specific columns
$names = $db->table('users')->select('id', 'name')->get();

// With conditions
$active = $db->table('users')
    ->where('status', 'active')
    ->where('role', 'admin')
    ->get();

// Comparison operators
$expensive = $db->table('products')
    ->where('price', '>', 100)
    ->orderBy('price', 'DESC')
    ->limit(10)
    ->get();

// Where IN
$selected = $db->table('users')
    ->whereIn('id', [1, 2, 3])
    ->get();

// Count
$total = $db->table('users')
    ->where('status', 'active')
    ->count();
```

### Insert

[](#insert)

```
// Via QueryBuilder — returns insert ID or false
$id = $db->table('users')->insert([
    'name' => 'John Doe',
    'email' => 'john@example.com',
]);
```

### Update

[](#update)

```
$affected = $db->table('users')
    ->where('id', 1)
    ->update(['status' => 'inactive']);
```

### Delete

[](#delete)

```
$affected = $db->table('users')
    ->where('id', 1)
    ->delete();
```

### Find by Primary Key

[](#find-by-primary-key)

```
// Uses Connection::find() directly (requires full table name)
$user = $db->find('wp_myplugin_users', 1);

// Custom primary key column
$item = $db->find('wp_myplugin_items', 'abc-123', 'uuid');
```

### Insert and Get ID

[](#insert-and-get-id)

```
// Uses Connection::insertGetId() directly (requires full table name)
$id = $db->insertGetId('wp_myplugin_users', [
    'name' => 'Jane Doe',
    'email' => 'jane@example.com',
]);
```

---

🔒 Transactions
--------------

[](#-transactions)

### Automatic (Recommended)

[](#automatic-recommended)

```
$orderId = $db->transaction(function () use ($db, $orderData, $paymentData) {
    $orderId = $db->table('orders')->insert($orderData);

    $db->table('payments')->insert([
        'order_id' => $orderId,
        ...$paymentData,
    ]);

    return $orderId;
});
```

### Manual

[](#manual)

```
$db->beginTransaction();

try {
    $db->table('orders')->insert($order);
    $db->table('inventory')
        ->where('product_id', $productId)
        ->update(['stock' => $newStock]);

    $db->commit();
} catch (\Throwable $e) {
    $db->rollback();
    throw $e;
}
```

---

🔍 Raw Queries
-------------

[](#-raw-queries)

All raw methods use `$wpdb->prepare()` when arguments are provided:

```
// Execute raw SQL
$db->query("UPDATE `{$table}` SET views = views + 1 WHERE id = %d", $id);

// Get a single row
$user = $db->getRow("SELECT * FROM `{$table}` WHERE email = %s", $email);

// Get multiple rows
$logs = $db->getResults("SELECT * FROM `{$table}` WHERE level = %s", 'error');

// Get a single value
$count = $db->getVar("SELECT COUNT(*) FROM `{$table}` WHERE status = %s", 'active');
```

---

🛠️ Error Handling
-----------------

[](#️-error-handling)

```
$db->table('users')->insert($data);

if ($db->hasError()) {
    $error = $db->lastError();  // Error message string
}

$affected = $db->rowsAffected();
$lastId = $db->lastInsertId();
```

---

📦 Related Packages
------------------

[](#-related-packages)

PackageDescription[wpzylos-core](https://github.com/WPDiggerStudio/wpzylos-core)Application foundation[wpzylos-migrations](https://github.com/WPDiggerStudio/wpzylos-migrations)Database migrations[wpzylos-scaffold](https://github.com/WPDiggerStudio/wpzylos-scaffold)Plugin template---

📖 Documentation
---------------

[](#-documentation)

- [Usage Guide](docs/usage.md) — Patterns, workflows, and examples
- [API Reference](docs/api-reference.md) — Complete class and method documentation
- [Full Documentation](https://wpzylos.com) — Online docs and tutorials

---

☕ Support the Project
---------------------

[](#-support-the-project)

- [GitHub Sponsors](https://github.com/sponsors/wpdiggerstudio)
- [PayPal Donate](https://www.paypal.com/donate/?hosted_button_id=66U4L3HG4TLCC)

---

📄 License
---------

[](#-license)

MIT License. See [LICENSE](LICENSE) for details.

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

---

**Made with ❤️ by [WPDiggerStudio](https://github.com/WPDiggerStudio)**

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance86

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

152d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/55980087?v=4)[WPDiggerStudio](/maintainers/WPDiggerStudio)[@WPDiggerStudio](https://github.com/WPDiggerStudio)

---

Top Contributors

[![WPDiggerStudio](https://avatars.githubusercontent.com/u/55980087?v=4)](https://github.com/WPDiggerStudio "WPDiggerStudio (10 commits)")

---

Tags

wordpressdatabaseormsqlquery builderwpdbwpzylos

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wpdiggerstudio-wpzylos-database/health.svg)

```
[![Health](https://phpackages.com/badges/wpdiggerstudio-wpzylos-database/health.svg)](https://phpackages.com/packages/wpdiggerstudio-wpzylos-database)
```

###  Alternatives

[berlindb/core

A collection of PHP classes and functions that aims to provide an ORM-like experience and interface to WordPress database tables.

271450.0k12](/packages/berlindb-core)[cycle/database

DBAL, schema introspection, migration and pagination

71777.8k53](/packages/cycle-database)[dbout/wp-orm

WordPress ORM with Eloquent.

12910.3k1](/packages/dbout-wp-orm)

PHPackages © 2026

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