NinjaDB

NinjaDB

Wordpress plugin

Install on Wordpress

App Details

A lightweight, expressive query builder for WordPress. NInjaDB use the same $wbdp instance and methods, It will help you to write $wpdb queries easily and expressively. At least PHP 5.3 is required.

It has some advanced features like:
– Query Like Laravel Basic Queries
– Where, orWhere methods
– Search data in all the columns or specific columns
– Easily Implement Pagination
– use insert, update or delete methods expressively.

The syntax is quite similar to Laravel’s query builder.

Simple Query:

The query below returns the row where id = 3, null if no rows.

$row = ninjaDB('my_table')->find(3); 

Full Queries:

$query = ninjaDB('my_table')->where('post_author', '=', 1); // for equal you can just use where('post_author, 1); // Get result as array of objects $query->get(); 

Full Usage API

### Initiate

// Select a table $query = ninjaDB()->table('post'); // post is the table name without prefix; 

OR You can pass your table name as an argument

// Select a table $query = ninjaDB('my_table'); // post is the table name without prefix;<h3>Query</h3> 

Get Easily

The query below returns the (first) row where id = 3, null if no rows.

$row = ninjaDB('my_table')->find(3); 

Access your row like, echo $row->name. If your field name is not id then pass the field name as second parameter ninjaDB('my_table')->find(3, 'author_id');.

The query below returns the all rows as array of objects where author_id = 3, null if no rows.

$result = ninjaDB('my_table')->findAll('author_id', 3); 

Select

$query = ninjaDB('my_table')->select('*'); 

Multiple Selects

->select(array('myfield1', 'myfield2', 'amyfield3')); 

Using select method multiple times select('a')->select('b') will also select a and b. Can be useful if you want to do conditional selects (within a PHP if).

Get All

Return an array of objects.

$query = ninjaDB('my_table')->where('author_id', 1); $result = $query->get(); 

You can loop through it like:

foreach ($result as $row) { echo $row->name; } 

Get First Row

$query = ninjaDB('my_table')->where('author_id', 1); $row = $query->first(); 

Returns the first row, or null if there is no record. Using this method you can also make sure if a record exists. Access these like echo $row->name.

Get Rows Count, MAX, MIN, AVerage, SUM

$query = ninjaDB('my_table')->where('author_id', 1); $count = $query->count(); $max = $query->max('views'); // Where `views` is the column name and all these will return integer / float $min = $query->min('views'); $avg = $query->avg('views'); $avg = $query->avg('views'); $sum = $query->sum('views'); 

Where

Basic syntax is (fieldname, operator, value), if you give two parameters then = operator is assumed. So where('name', 'jewel') and where('name', '=', 'jewel') is the same.

ninjaDB('my_table') ->where('name', '=', 'jewel') ->whereNot('age', '>', 25) ->orWhere('description', 'LIKE', '%query%'); 

whereIn

ninjaDB('my_table') ->whereIn( 'id', array(1,2,3) ) ->get(); 

Limit and Offset

->limit(30); ->offset(10); // or you can use aliases ->take(30); ->skip(10); 

Order By

->orderBy('id', 'ASC'); 

Insert

$data = array( 'name' => 'Jewel', 'description' => 'Hello, There' ); $insertId = ninjaDB('my_table')->insert($data); insert() method returns the insert id. optionally you can pass $format of your data as `->insert($data, $format);` where `$format` is an array of formats to be mapped to each of the value in $data 

Batch Insert

$data = array( array( 'name' => 'Jewel', 'description' => 'Hello, There' ), array( 'name' => 'Adre', 'description' => 'Hello, I am Adre Astrian' ), ); $insertIds = ninjaDB('my_table')->batch_insert($data); 

In case of batch insert, it will return an array of insert ids.

Update

$data = array( 'name' => 'Shahjahan Jewel', 'description' => 'Hello, There' ); ninjaDB('my_table')->where('id', 5)->update($data); 

Will update the name field to Shahjahan Jewel and description field to Hello, There where id = 5.

Delete

ninjaDB('my_table')->where('id', '>', 5)->delete(); 

Will delete all the rows where id is greater than 5.

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

TODO

  • [ ] join()
  • [x] whereIN()
  • [ ] whereNotIN()
  • [ ] whereBetween
  • [ ] whereNotBetween
  • [ ] Having
  • [ ] GroupBy
  • [x] selectDistinct

If you would like to implement any of the TODO please feel free to do and do a pull request

And, finally, consider to contribute to this plugin here.

Pricing

Starting from $0 per month.

Check Out the Consent Form Widget

By Common Ninja

Consent FormTry For Free!

App Info

Rating

Reviewers

No reviews

Tags

No tags

Developed By

Shahjahan Jewel

Quick & Easy

Find the Best Wordpress plugins for you

Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!

Testimonial

Testimonial plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Maps

Maps plugins for Wordpress

Translation

Translation plugins for Wordpress

Chat

Chat plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Contact

Contact plugins for Wordpress

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Forms

Forms plugins for Wordpress

Comments

Comments plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Comments

Comments plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Video Player

Video Player plugins for Wordpress

popup

popup plugins for Wordpress

SiteMap

SiteMap plugins for Wordpress

Payment

Payment plugins for Wordpress

Coming Soon

Coming Soon plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Sliders

Sliders plugins for Wordpress

Analytics

Analytics plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Security

Security plugins for Wordpress

Ads

Ads plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Membership

Membership plugins for Wordpress

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Common Ninja Apps

Some of the best Common Ninja plugins for Wordpress

Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.

Consent Form for Wordpress logo

Consent Form

Create consent forms that collect signatures, save submissions, send notifications, and help you manage approvals efficiently.

Scores Board for Wordpress logo

Scores Board

Show rankings and performance data on your site with a customizable scores board that motivates participation and keeps users engaged.

Call Button for Wordpress logo

Call Button

Add a call button to your site so visitors can tap to start a phone call instantly, improving direct communication access.

World Clock for Wordpress logo

World Clock

Display multiple time zones with a world clock widget that offers clear global times, customizable styles, and a responsive design for better user experience.

Community Sentiment for Wordpress logo

Community Sentiment

Turn visitor opinions into instant community insights

Facebook Reviews for Wordpress logo

Facebook Reviews

Show Facebook reviews to build trust, improve credibility, and help visitors make confident purchase decisions that support higher sales.

Form Builder for Wordpress logo

Form Builder

Create custom forms with a form builder that offers advanced field types, easy layout control, and flexible options for any purpose.

Sitejabber Reviews for Wordpress logo

Sitejabber Reviews

Show Sitejabber reviews to build trust, strengthen credibility, and help visitors make confident purchase decisions that support higher sales.

Bluesky Feed for Wordpress logo

Bluesky Feed

Show Bluesky posts with a Bluesky feed that updates in real time, improves content discovery, and keeps visitors engaged with fresh activity.

Highlighted Headlines for Wordpress logo

Highlighted Headlines

Enhance titles with highlighted headlines that use custom colors, animations, and styles to draw attention and help visitors notice key messages.

Stories for Wordpress logo

Stories

Add interactive stories to your site to showcase content in a visual, mobile-friendly format that boosts engagement and guides visitors toward action.

March Madness Bracket Maker for Wordpress logo

March Madness Bracket Maker

Create interactive March Madness brackets where users can make predictions, track tournament progress, and compete with others throughout every round.

Discover Apps By Platform

Discover the best apps for your website

WordPress
Wix
Shopify
Weebly
Webflow
Joomla
PrestaShop
Shift4Shop
WebsiteX5
MODX
Opencart
NopCommerce

Common Ninja Search Engine

The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!

Multiple platforms