Calling stored procedure in wordpress using wpdb

Today I was get stuck while calling stored procedure in wordpress. Neither $wpdb->get_results nor $wpdb->get_results was working. I got the point somrthing was went wrong. The output of  $wpdb->show_errors() is nothing so there was not an error.

This is a create statement of my procedure I’m tried to called it using $wpdb

CREATE PROCEDURE posts_count(OUT @total_posts INT)
SELECT COUNT(*)  INTO total_posts FROM wp_posts;

Okay so I get to knew while try and test try and test

$result = $wpdb->query("CALL posts_count(@total_posts)");
$result = $wpdb->get_results("SELECT @total_posts");
var_dump( $result );

So finally it working. It is returning me a correct output

array (size=1)
0 =>
public '@total_posts' => string '19' (length=2)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s