Mysql Query Builder for WordPress

1.2.0 2023-01-09 09:32 UTC

This package is auto-updated.

Last update: 2023-03-14 19:54:52 UTC


Relational Database Query builder for WordPress. WP Query Builder uses PDO for database queries. It has zero dependencies with third-party query builders or any other composer library.


Documentation website here.


Create Table


Insert Statement

DB::insert('querybuilder', [
        'name' => 'Keramot UL Islam',
        'email' => '',

Update Statement

DB::update('querybuilders', [
    'name' => 'Keramot UL',
    'email' => ''
->where('ID', '=', 10)
->andWhere('name', '=', 'Abm Sourav')

Select Statement

$result =
DB::select('qb.ID', ',')

// *** where clouse
$result =
DB::select('posts.ID', 'posts.post_title')
    ->from('posts posts')
    ->where('posts.post_status', '=', 'publish')
    ->orderBy('post_title', 'DESC')

// *** JOIN
DB::select('users.display_name name')
    ->count('posts.ID', 'posts')
    ->from('users users')
    ->join('posts posts')
    ->where('posts.post_status', '=', 'publish')
    ->andWhere('posts.post_type', '=', 'post')

// raw sql
    ->from('posts posts')
    ->raw("WHERE posts.post_type = 'post'")
    ->andWhere('posts.post_status', '=', 'publish')
    ->raw("LIMIT 10")

Delete Statement

// delete one row
    ->where('ID', '=', 3)

// delete all records

Drop Statement


Single instence

Expressions also can be exicuted with one instence of DB class. By doing this database connection will be stablished only once.

$db = new DB();

$result =
$db::select('posts.ID', 'posts.post_title')


Database Connection

By default database connection will set out of the box, automaically. But if you can also manually input database configurations.

$db = new DB();
    "dbhost"        => <mysql host>,
    "dbname"        => <database name>,
    "dbuser"        => <database username>,
    "dbpassword"    => <database password>,
    "prefix"        => <database table prefix>


The default driver is PDO. But if you want to use wpdb which uses Mysqli, you also can do that by changing the driver.

$db = new DB();

    ->from('posts posts')

Dev Envirenment Setup for Contributors

Want to contribute to this package? Please follow the steps below.

  • Create a local WordPress envirenment setup.
  • Create a basic plugin.
  • Run composer init into the plugin.
  • Clone into plugin folder.
  • Add repository for local package in plugin's composer.json.
            "repositories": [
                    "type": "path",
                    "url": "./howdy_qb"
  • Require this package. composer require "codesvault/howdy-qb @dev"