
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(); ### 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> 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); $query = ninjaDB('my_table')->select('*'); ->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).
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; } $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.
$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'); 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%'); ninjaDB('my_table') ->whereIn( 'id', array(1,2,3) ) ->get(); ->limit(30); ->offset(10); // or you can use aliases ->take(30); ->skip(10);
->orderBy('id', 'ASC'); $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 $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.
$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.
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.
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.
Starting from $0 per month.
Rating
Reviewers
No reviews
Tags
Developed By
Shahjahan Jewel
Quick & Easy
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 plugins for Wordpress
Contact Form plugins for Wordpress
Maps plugins for Wordpress
Translation plugins for Wordpress
Chat plugins for Wordpress
Slider plugins for Wordpress
Reviews plugins for Wordpress
Contact plugins for Wordpress
Galleries plugins for Wordpress
SEO plugins for Wordpress
Forms plugins for Wordpress
Comments plugins for Wordpress
Backup plugins for Wordpress
Privacy plugins for Wordpress
Optimize plugins for Wordpress
Tabs plugins for Wordpress
Social Sharing plugins for Wordpress
Events Calendar plugins for Wordpress
Comments plugins for Wordpress
Social Feeds plugins for Wordpress
Social Sharing plugins for Wordpress
Portfolio plugins for Wordpress
Video Player plugins for Wordpress
popup plugins for Wordpress
SiteMap plugins for Wordpress
Payment plugins for Wordpress
Coming Soon plugins for Wordpress
Inventory plugins for Wordpress
Testimonials plugins for Wordpress
Portfolio plugins for Wordpress
Membership plugins for Wordpress
Forms plugins for Wordpress
Analytics plugins for Wordpress
Events Calendar plugins for Wordpress
Sliders plugins for Wordpress
Analytics plugins for Wordpress
Reviews plugins for Wordpress
Security plugins for Wordpress
Ads plugins for Wordpress
Music Player plugins for Wordpress
Countdown plugins for Wordpress
Email Marketing plugins for Wordpress
Membership plugins for Wordpress
Ecommerce plugins for Wordpress
Customer Support plugins for Wordpress
Video Player plugins for Wordpress
Tabs plugins for Wordpress
Social Feeds plugins for Wordpress
Common Ninja Apps
Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.

Create consent forms that collect signatures, save submissions, send notifications, and help you manage approvals efficiently.
Show rankings and performance data on your site with a customizable scores board that motivates participation and keeps users engaged.
Add a call button to your site so visitors can tap to start a phone call instantly, improving direct communication access.
Display multiple time zones with a world clock widget that offers clear global times, customizable styles, and a responsive design for better user experience.

Turn visitor opinions into instant community insights
Show Facebook reviews to build trust, improve credibility, and help visitors make confident purchase decisions that support higher sales.
Create custom forms with a form builder that offers advanced field types, easy layout control, and flexible options for any purpose.
Show Sitejabber reviews to build trust, strengthen credibility, and help visitors make confident purchase decisions that support higher sales.
Show Bluesky posts with a Bluesky feed that updates in real time, improves content discovery, and keeps visitors engaged with fresh activity.
Enhance titles with highlighted headlines that use custom colors, animations, and styles to draw attention and help visitors notice key messages.
Add interactive stories to your site to showcase content in a visual, mobile-friendly format that boosts engagement and guides visitors toward action.
Create interactive March Madness brackets where users can make predictions, track tournament progress, and compete with others throughout every round.
More plugins
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!
