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 Personality Quiz Widget

By Common Ninja

Personality QuizTry 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.

Personality Quiz for Wordpress logo

Personality Quiz

Create interactive personality quizzes with custom results and flexible design to boost engagement and help visitors explore tailored outcomes easily.

Job Listings for Wordpress logo

Job Listings

Create job listings with a jobs board widget that lets you post openings, manage roles easily, and help candidates find the right positions quickly.

Restaurant Menu for Wordpress logo

Restaurant Menu

Create an online restaurant menu that organizes dishes, highlights key items, and helps visitors explore options with confidence.

Website Translator for Wordpress logo

Website Translator

Add a translation widget to your site so users can switch languages easily and access content in their preferred language.

Petition Form for Wordpress logo

Petition Form

Gather supporter signatures with a petition form that collects entries, saves submissions, sends notifications, and helps you drive meaningful change efficiently.

Tilted Image for Wordpress logo

Tilted Image

Use tilted image effects to rotate visuals, add creative style, and keep visitors engaged with dynamic images on your site.

Mastodon Feed for Wordpress logo

Mastodon Feed

Show Mastodon posts in a live Mastodon feed that keeps content fresh, strengthens your social presence, and helps visitors engage with your updates.

AI Chatbot for Wordpress logo

AI Chatbot

Add an AI chatbot that answers user questions by crawling your site, using uploaded content, and collecting chat interactions.

Order Form for Wordpress logo

Order Form

Use an order form to let customers submit product orders, save entries, receive notifications, and collect payments through PayPal or Stripe for a smoother buying experience.

Reddit Feed for Wordpress logo

Reddit Feed

Show Reddit posts with a Reddit feed that updates automatically, improves content discovery, and keeps visitors engaged with fresh discussions.

TikTok Feed for Wordpress logo

TikTok Feed

Show your latest TikTok videos in a live feed that keeps content fresh, builds social proof, and keeps visitors engaged.

Agenda for Wordpress logo

Agenda

Add an event agenda to your site to display schedules clearly, helping users understand timing and plan their attendance.

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