WordPress vs. Other Modern PHP Frameworks: ORM Comparison
Modern PHP frameworks like Laravel or Symfony use ORMs (Object-Relational Mapping) to deal with databases.
Laravel uses Eloquent, a composer package which follows the Active Record pattern, while Symfony utilizes Doctrine, which follows the Data Mapper pattern.
An example code with Laravel Eloquent would look like this:
$users = User::where(‘status’, ‘active’)
->orderBy(‘created_atp’, ‘desc’)
->take(10)
->get();Here, we don’t need to worry about SQL injection attacks.
Get Yousef Fatouraee’s stories in your inbox
Join Medium for free to get updates from this writer.
WordPress, on the other hand, as the most used PHP framework, not only uses any ORMs, but also it doesn’t strictly follow the MVC (Model-View-Controller) architecture pattern!
Instead, it follows its own architectural pattern, which can be described as a mix of procedural and object-oriented programming paradigms.
The same query, in WordPress, would look like this:
global $wpdb;
$query = “SELECT * FROM {$wpdb->prefix}users
WHERE user_status = ‘0’
ORDER BY user_registered DESC
LIMIT 10”;
$users = $wpdb->get_results($query);Yet, in order to check query injection, $wpdb->prepare( ) should also be called.
Learn more:
https://developer.wordpress.org/reference/classes/wpdb/
https://laravel.com/docs/eloquent



