• Hi Friends,

    I need to call a mysql Stored procedure from WordPress plugin. How can I do that?

    $sql = “CALL foodtyp_radius($unit, $foodtype, $distance, $precision, $srclat, $srclong)”;

    $foodresults = $wpdb->get_results($sql);

    I get this error:

    WordPress database error: [PROCEDURE wordpress.foodtyp_radius can't return a result set in the given context]

    Please can anyone help.

    thanks & regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello, i’v found a start of solution, just take a look on my post.

    Cya
    Shaan

    After 4 month here the solution :

    Search for : ( file wd-db.php )

    function query( $query ) {
    		if ( ! $this->ready )
    			return false;
    
    		// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
    		if ( function_exists( 'apply_filters' ) )
    			$query = apply_filters( 'query', $query );'

    and replace with :

    function query( $query ) {
    		if ( ! $this->ready )
    			return false;
    
        if ( strpos($query, "CALL") === false )
        {
              $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
              $this->set_charset( $this->dbh );
              $this->ready = true;
              $this->select( $this->dbname, $this->dbh );
        }
        else
        {
              $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, false,65536 );
              $this->set_charset( $this->dbh );
              $this->ready = true;
              $this->select( $this->dbname, $this->dbh );
        }
    
    		// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
    		if ( function_exists( 'apply_filters' ) )
    			$query = apply_filters( 'query', $query );

    Now you should be able to run stored procedures.

    By the way this code is like Mac Gyver tips ??

    Maybe the WordPress team could set it in the next release ??

    Shaan

    Perhaps you could introduce this as a proposed patch at https://core.trac.www.remarpro.com

    Indeed it would be quite useful of some of WP’s internals themselves were moved into Stored Procedures. This could, for example, eliminate problems with local time fields versus GMT dates.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to call Stored procedure from Plugin’ is closed to new replies.