4 ms·
In WordPress the string concatenation in SQL is normal, even on the very first example: $results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}option
by Ciantic 5y ago
In WordPress the string concatenation in SQL is normal, even on the very first example:
$results = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_id = 1", OBJECT );
This is because the database tables aren't static, so one must add prefix to each table from a variable. It's horrible, it would have been far better if there was magic string like %PREFIX% to avoid that.
[1]: https://developer.wordpress.org/reference/classes/wpdb/#using-the-wpdb-global-object https://developer.wordpress.org/reference/classes/wpdb/#usin...
- simondotau 5y agoOr even better if they didn't treat tables like confetti. I haven't analysed the wordpress schema closely but on first blush it looks like a hacky premature optimisation to solve a problem, either one of performance, or data isolation, or to avoid unravelling use of magic numbers. Realistically, content within the same "universe" should co-mingle in the same table. Multiple "universes" of content should be isolated into their own database/schema, which $wpdb should pre-select upon connection. "SELECT * FROM options WHERE prefix = ? AND option_id = 241"