WordPress.org

Ready to get started?Download WordPress

Forums

WordPress and Stored procedure (2 posts)

  1. shaan1974
    Member
    Posted 2 years ago #

    Hi all,
    i'm new in wordpress, i'v try to run stored procedures in wordpress in a custome page like this :

    $sql="CALL test1();";
    
                        $posts = $wpdb->get_results($sql);
    
                        print("<ul>");
                        foreach ($posts as $post)
                        {
                            print('<li>'.$post->TP.'|'.$post->STP.'<br/>');
                             print('</li>');
                        }
                        print("</ul>");

    but an error return :
    "WordPress database error: [PROCEDURE sgo.test1 can't return a result set in the given context]"

    So i'v found a solution to be able to run stored procedure.

    In file "wp-dp.php" in function "db_connect()" you have to replace the end of the mysql_connect line :

    $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );

    with :

    $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, false,65536 );

    But... since i'v modified this line some plugins have some problems to executes their own queries.

    Some one have a solution ?

    Thanks
    Shaan

  2. shaan1974
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic