Create a stored procedure on plugin activation

As an example, let’s say you were planning on the following stored procedure:

SELECT * FROM wp_posts

Instead of actually stashing this inside MySQL, let’s create a PHP function:

function {plugin_prefix}_get_posts() {
    global $wpdb;

    return $wpdb->get_results( "SELECT * FROM $wpdb->posts" );
}

Now we can call this whenever we need it:

$posts = {plugin_prefix}_get_posts();
// Away we go!

I’ve intentionally used invalid PHP to save the future copy-pasters from themselves – rename the function to something specific to your project!