• 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

Viewing 1 replies (of 1 total)
  • Thread Starter shaan1974

    (@shaan1974)

    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

Viewing 1 replies (of 1 total)
  • The topic ‘WordPress and Stored procedure’ is closed to new replies.