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 Contact Form Widget

By Common Ninja

Contact 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

Galleries

Galleries plugins for Wordpress

SEO

SEO plugins for Wordpress

Contact Form

Contact Form plugins for Wordpress

Forms

Forms plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Social Sharing

Social Sharing 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

Comments

Comments plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Maps

Maps plugins for Wordpress

Security

Security plugins for Wordpress

Translation

Translation plugins for Wordpress

Ads

Ads plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Music Player

Music Player plugins for Wordpress

Backup

Backup plugins for Wordpress

Privacy

Privacy plugins for Wordpress

Optimize

Optimize plugins for Wordpress

Chat

Chat plugins for Wordpress

Countdown

Countdown plugins for Wordpress

Email Marketing

Email Marketing plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Membership

Membership 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

Ecommerce

Ecommerce plugins for Wordpress

Customer Support

Customer Support plugins for Wordpress

Inventory

Inventory plugins for Wordpress

Video Player

Video Player plugins for Wordpress

Testimonials

Testimonials plugins for Wordpress

Tabs

Tabs plugins for Wordpress

Social Sharing

Social Sharing plugins for Wordpress

Social Feeds

Social Feeds plugins for Wordpress

Slider

Slider plugins for Wordpress

Reviews

Reviews plugins for Wordpress

Portfolio

Portfolio plugins for Wordpress

Membership

Membership plugins for Wordpress

Forms

Forms plugins for Wordpress

Events Calendar

Events Calendar plugins for Wordpress

Contact

Contact plugins for Wordpress

Comments

Comments plugins for Wordpress

Analytics

Analytics 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.

Contact Form for Wordpress logo

Contact Form

Use a contact form so visitors can send messages, submit inquiries, and help you collect leads and improve user experience.

Telegram Chat for Wordpress logo

Telegram Chat

Add Telegram Chat to your site to communicate with visitors, deliver instant support, and provide a smoother, more reliable user experience.

Progress Bars for Wordpress logo

Progress Bars

Show progress clearly with animated progress bars that visualize goals, highlight achievements, and keep visitors engaged and motivated.

Course Registration Form for Wordpress logo

Course Registration Form

Use a scroll progress bar that visually tracks reading on the page, improves navigation, and keeps visitors aware of their position.

Course Listings for Wordpress logo

Course Listings

Create course listings with a course catalog widget that displays programs clearly, supports easy organization, and helps visitors explore courses effectively.

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.

Link In Bio for Wordpress logo

Link In Bio

Create a branded home for all your links and content.

Social Votes for Wordpress logo

Social Votes

Encourage interaction with social votes that let visitors like, upvote, and rank content, boosting engagement and guiding better decisions.

RSS Feed Slider for Wordpress logo

RSS Feed Slider

Show RSS feed updates with an RSS feed slider that auto updates, displays posts in a smooth layout, and keeps visitors engaged.

Quiz Maker for Wordpress logo

Quiz Maker

Create interactive quizzes with a quiz maker that lets you build custom questions, collect responses, and increase engagement with easy site integration.

Messenger Chat for Wordpress logo

Messenger Chat

Add Messenger Chat to your site to communicate with visitors, offer fast support, and create a smoother user experience across all pages.

Charts & Graphs for Wordpress logo

Charts & Graphs

Add charts and graphs to your site to present data clearly, help visitors understand insights faster, and support more confident decision making.

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