
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
Galleries plugins for Wordpress
SEO plugins for Wordpress
Contact Form plugins for Wordpress
Forms plugins for Wordpress
Social Feeds plugins for Wordpress
Social Sharing plugins for Wordpress
Events Calendar plugins for Wordpress
Sliders plugins for Wordpress
Analytics plugins for Wordpress
Reviews plugins for Wordpress
Comments plugins for Wordpress
Portfolio plugins for Wordpress
Maps plugins for Wordpress
Security plugins for Wordpress
Translation plugins for Wordpress
Ads plugins for Wordpress
Video Player plugins for Wordpress
Music Player plugins for Wordpress
Backup plugins for Wordpress
Privacy plugins for Wordpress
Optimize plugins for Wordpress
Chat plugins for Wordpress
Countdown plugins for Wordpress
Email Marketing plugins for Wordpress
Tabs plugins for Wordpress
Membership plugins for Wordpress
popup plugins for Wordpress
SiteMap plugins for Wordpress
Payment plugins for Wordpress
Coming Soon plugins for Wordpress
Ecommerce plugins for Wordpress
Customer Support plugins for Wordpress
Inventory plugins for Wordpress
Video Player plugins for Wordpress
Testimonials plugins for Wordpress
Tabs plugins for Wordpress
Social Sharing plugins for Wordpress
Social Feeds plugins for Wordpress
Slider plugins for Wordpress
Reviews plugins for Wordpress
Portfolio plugins for Wordpress
Membership plugins for Wordpress
Forms plugins for Wordpress
Events Calendar plugins for Wordpress
Contact plugins for Wordpress
Comments plugins for Wordpress
Analytics 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.
Use a contact form so visitors can send messages, submit inquiries, and help you collect leads and improve user experience.
Add Telegram Chat to your site to communicate with visitors, deliver instant support, and provide a smoother, more reliable user experience.
Show progress clearly with animated progress bars that visualize goals, highlight achievements, and keep visitors engaged and motivated.
Use a scroll progress bar that visually tracks reading on the page, improves navigation, and keeps visitors aware of their position.
Create course listings with a course catalog widget that displays programs clearly, supports easy organization, and helps visitors explore courses effectively.
Show Reddit posts with a Reddit feed that updates automatically, improves content discovery, and keeps visitors engaged with fresh discussions.
Create a branded home for all your links and content.
Encourage interaction with social votes that let visitors like, upvote, and rank content, boosting engagement and guiding better decisions.
Show RSS feed updates with an RSS feed slider that auto updates, displays posts in a smooth layout, and keeps visitors engaged.
Create interactive quizzes with a quiz maker that lets you build custom questions, collect responses, and increase engagement with easy site integration.
Add Messenger Chat to your site to communicate with visitors, offer fast support, and create a smoother user experience across all pages.
Add charts and graphs to your site to present data clearly, help visitors understand insights faster, and support more confident decision making.
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!
