PHPackages                             claytonkreisel/wpdb-tools - 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. claytonkreisel/wpdb-tools

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

claytonkreisel/wpdb-tools
=========================

This package provides tools to be used in custom WordPress themes or plugins that aid you in using the WPDB especially in the creation of custom tables

v1.1.2(4y ago)5420MITPHPPHP &gt;=7.0

Since Jun 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/claytonkreisel/wpdb-tools)[ Packagist](https://packagist.org/packages/claytonkreisel/wpdb-tools)[ Docs](https://github.com/claytonkreisel/wpdb-tools)[ RSS](/packages/claytonkreisel-wpdb-tools/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)DependenciesVersions (12)Used By (0)

WordPress Database Table Tools
==============================

[](#wordpress-database-table-tools)

A package to aid in WordPress theme and plugin development by adding classes that quickly allow you to add and manage custom tables to the WordPress database. This uses native WordPress API functions and makes it easy to setup model based I/O using abstract parent classes.

PHP Version Requirements
------------------------

[](#php-version-requirements)

Version 1 of this library should work on **PHP 7.4** or newer.

How to Install
--------------

[](#how-to-install)

#### Composer Install

[](#composer-install)

```
composer require claytonkreisel/wpdb-tools
```

or

#### Manual Install

[](#manual-install)

Download the package and manually place it in your application then simply include the `autoload.php` file like this at the beginning of your application:

```

```

How to Use
----------

[](#how-to-use)

### Custom Tables

[](#custom-tables)

This library contains a parent abstract class of `Table`. This class allows you to create a child class that will manage your database columns using an array defined in a child method and provides you with methods to `insert`, `select`, `update` and `delete` rows within that table.

#### Creating a Custom Table Class

[](#creating-a-custom-table-class)

In order to create a custom table you will create a child class that extends the `Table` class within this package.

***NOTE:*** If you wish to create a table that also has a relational "metadata" table much like the `post` and `postmeta` structure native to WordPress then please refer to the `TableMeta` class. This class will simply create a single table without a corresponding meta table. That class will create and manage both the main table and the metadata table without the need of defining a `Table` class.

To create a `Table` you will put the following code in your `functions.php` file or another file that is included in your plugin or theme. This assumes you have already installed or included the classes through composer or manually.

```

```

After you have written this code you can now create a new instance of this class. Upon construction this class will fire a method that checks to see if the version of the database has changed. If it has then a database altering and cleanup will occur.

***NOTE:*** Columns that are removed from the columns array method will remain in the database until you explicitly remove them using the `remove_column` method. This is to protect from accidental deletion of data.

```

```

#### Inserting a Row in a Custom Table

[](#inserting-a-row-in-a-custom-table)

In order to insert a new row into a custom table you simply call the `insert` method on the object you initiated.

```

```

#### Inserting Multiple Rows in a Custom Table

[](#inserting-multiple-rows-in-a-custom-table)

In order to insert multiple rows into a custom table you simply call the `insert` method on the object you initiated with multiple associative arrays of data as the `$data` parameter.

***NOTE:*** In order for this method to work properly the same keys must be passed in each iteration of the associative array.

```
