Leave a Reply

1 comment

  1. You want to use the wpdb. It is a very simple wrapper around PHP’s mysql (yes, mysql) functions.

    $results = $wpdb->query($your_complicated query); // Congrats on actually knowing how to write SQL :)
    

    You can feed any valid SQL into that methaod and it should work just like any query but you can’t “stack” queries. mysql and PDO do allow stacked queries (though I am not really a fan of them, being paranoid and all), but, as mentioned wpdb still uses mysql functions.

    You should also replace your hard-coded WordPress table names with the $wpdb equivalents. For example, instead of wp_posts use $wpdb->posts. The reason for this is thatwp_ prefix is changable. It is the default and it very common but can be changed, and changed easily. It is just a simple edit to wp-config.php.